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