Skip to content

Commit 997fb8a

Browse files
authored
Java program to print the nodes.
1 parent 9fd3485 commit 997fb8a

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

HashMap.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
4+
public class Hashmap
5+
{
6+
public static void main(String[] args)
7+
{
8+
HashMap<String, Integer> map = new HashMap<>();
9+
print(map);
10+
map.put("abc", 10);
11+
map.put("mno", 30);
12+
map.put("xyz", 20);
13+
14+
System.out.println("Size of map is" + map.size());
15+
16+
print(map);
17+
if (map.containsKey("abc"))
18+
{
19+
Integer a = map.get("abc");
20+
System.out.println("value for key \"abc\" is:- " + a);
21+
}
22+
map.clear();
23+
print(map);
24+
}
25+
public static void print(Map<String, Integer> map)
26+
{
27+
if (map.isEmpty())
28+
{
29+
System.out.println("map is empty");
30+
}
31+
else
32+
{
33+
System.out.println(map);
34+
}
35+
}
36+
}
37+
On executing the HashMap program, output goes like this:
38+
39+
1
40+
2
41+
3
42+
4
43+
5
44+
map is empty
45+
Size of map is:- 3
46+
{abc=10, xyz=20, mno=30}
47+
value for key "abc" is:- 10
48+
map is empty

0 commit comments

Comments
 (0)