-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha57hashMap.java
More file actions
41 lines (32 loc) · 1.15 KB
/
a57hashMap.java
File metadata and controls
41 lines (32 loc) · 1.15 KB
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
import java.util.*;
public class a57hashMap {
public static void main(String[] args) {
HashMap<String, Integer> hm = new HashMap<>();
// put operation in hashmap
hm.put("India", 100);
hm.put("China", 50);
hm.put("Usa", 70);
System.out.println(hm);
// get operation in hashmap
int population = hm.get("India");
System.out.println(population);
// contains operation in hashmap
System.out.println(hm.containsKey("Usa"));
// remove operation in hashmap
System.out.println(hm.remove("Usa"));
System.out.println(hm);
// size of hashmap
System.out.println("Size - " + hm.size());
// isEmpty operation in hashmap
System.out.println(hm.isEmpty());
// clear operation in hashmap
// hm.clear();
// System.out.println("Hashmap - "+hm);
// iteration on hashmap
Set<String> keys = hm.keySet();
System.out.println(keys);
for (String k : keys) {
System.out.println("keys : " + k + ", Value : " + hm.get(k));
}
}
}