File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ // Java program to illustrate
2+ // Java.util.HashMap
3+
4+ import java .util .HashMap ;
5+ import java .util .Map ;
6+
7+ public class GFG {
8+ public static void main (String [] args )
9+ {
10+
11+ HashMap <String , Integer > map
12+ = new HashMap <>();
13+
14+ print (map );
15+ map .put ("vishal" , 10 );
16+ map .put ("sachin" , 30 );
17+ map .put ("vaibhav" , 20 );
18+
19+ System .out .println ("Size of map is:- "
20+ + map .size ());
21+
22+ print (map );
23+ if (map .containsKey ("vishal" )) {
24+ Integer a = map .get ("vishal" );
25+ System .out .println ("value for key"
26+ + " \" vishal\" is:- "
27+ + a );
28+ }
29+
30+ map .clear ();
31+ print (map );
32+ }
33+
34+ public static void print (Map <String , Integer > map )
35+ {
36+ if (map .isEmpty ()) {
37+ System .out .println ("map is empty" );
38+ }
39+
40+ else {
41+ System .out .println (map );
42+ }
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments