File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ package hashing ;
2
+
3
+ import java .util .*;
4
+ class HashMap {
5
+ public static void main (String args []){
6
+ HashMap <Integer ,String > hm =new HashMap <Integer ,String >();
7
+ System .out .println ("Initial list of elements: " +hm );
8
+ hm .put (100 ,"Amit" );
9
+ hm .put (101 ,"Vijay" );
10
+ hm .put (102 ,"Rahul" );
11
+
12
+ System .out .println ("After invoking put() method " );
13
+ for (Map .Entry m :hm .entrySet ()){
14
+ System .out .println (m .getKey ()+" " +m .getValue ());
15
+ }
16
+
17
+ hm .putIfAbsent (103 , "Gaurav" );
18
+ System .out .println ("After invoking putIfAbsent() method " );
19
+ for (Map .Entry m :hm .entrySet ()){
20
+ System .out .println (m .getKey ()+" " +m .getValue ());
21
+ }
22
+ HashMap <Integer ,String > map =new HashMap <Integer ,String >(); // another object map
23
+ map .put (104 ,"Ravi" );
24
+ map .putAll (hm );
25
+ System .out .println ("After invoking putAll() method " );
26
+ for (Map .Entry m :map .entrySet ()){
27
+ System .out .println (m .getKey ()+" " +m .getValue ());
28
+ }
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments