diff --git a/Hashmap b/Hashmap new file mode 100644 index 0000000..e4c0c2e --- /dev/null +++ b/Hashmap @@ -0,0 +1,34 @@ +import java.util.*; + +//////////////////naveen hashmap +class HashMap3{ + public static void main(String args[]){ + HashMap hm=new HashMap(); + hm.put(100,"Amit"); + hm.put(101,"Vijay"); + hm.put(102,"Rahul"); + System.out.println("Initial list of elements:"); + for(Map.Entry m:hm.entrySet()) + { + System.out.println(m.getKey()+" "+m.getValue()); + } + System.out.println("Updated list of elements:"); + hm.replace(102, "Gaurav"); + for(Map.Entry m:hm.entrySet()) + { + System.out.println(m.getKey()+" "+m.getValue()); + } + System.out.println("Updated list of elements:"); + hm.replace(101, "Vijay", "Ravi"); + for(Map.Entry m:hm.entrySet()) + { + System.out.println(m.getKey()+" "+m.getValue()); + } + System.out.println("Updated list of elements:"); + hm.replaceAll((k,v) -> "Ajay"); + for(Map.Entry m:hm.entrySet()) + { + System.out.println(m.getKey()+" "+m.getValue()); + } + } +}