-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathhashmap.java
More file actions
44 lines (35 loc) · 773 Bytes
/
hashmap.java
File metadata and controls
44 lines (35 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Java program to illustrate
// Java.util.HashMap
import java.util.HashMap;
import java.util.Map;
public class GFG {
public static void main(String[] args)
{
HashMap<String, Integer> map
= new HashMap<>();
print(map);
map.put("vishal", 10);
map.put("sachin", 30);
map.put("vaibhav", 20);
System.out.println("Size of map is:- "
+ map.size());
print(map);
if (map.containsKey("vishal")) {
Integer a = map.get("vishal");
System.out.println("value for key"
+ " \"vishal\" is:- "
+ a);
}
map.clear();
print(map);
}
public static void print(Map<String, Integer> map)
{
if (map.isEmpty()) {
System.out.println("map is empty");
}
else {
System.out.println(map);
}
}
}