Saturday, January 27, 2018

HashMap In Java



import java.util.HashMap;
import java.util.Map;

public class HashMapExample {
    public static void print(Map<String,Integer> map) {
   
        if(map.isEmpty()) {
            System.out.println(" Map Is Empty !");
        } else {
            System.out.println("Size Of Map = "+map.size());
            System.out.println(map);
        }
       
    }
    public static void main(String arg[]) {
        HashMap<String  ,Integer> map=new HashMap<>();
        print(map);
        map.put("brij",26);
        map.put("vijay",20);
        map.put("anil",30);
        print(map);
        if(map.containsKey("brij")) {
            System.out.println(" The Value of key is ="+map.get("brij"));
        }
    }
}

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...