Skip to content

Commit

Permalink
Create Hashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Naveenkumarsahu9795 authored Oct 3, 2023
1 parent 6d97418 commit 7093e51
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Hashmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.*;

//////////////////naveen hashmap
class HashMap3{
public static void main(String args[]){
HashMap<Integer,String> hm=new HashMap<Integer,String>();
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());
}
}
}

0 comments on commit 7093e51

Please sign in to comment.