-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashing.java
47 lines (36 loc) · 1.18 KB
/
Hashing.java
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
45
46
47
import java.util.*;
public class Hashing {
public static void main(String args[]) {
//Creation
HashMap<String, Integer> map = new HashMap<>();
//Insertion
map.put("UG", 120);
map.put("USA", 30);
map.put("India", 150);
System.out.println(map);
map.put("India", 180);
System.out.println(map);
//Searching
if(map.containsKey("Indonesia")) {
System.out.println("key is present in the map");
} else {
System.out.println("key is not present in the map");
}
//searching (2)
System.out.println(map.get("India")); //key exists
System.out.println(map.get("Indonesia")); //key doesn't exist
//Iteration (1)
for( Map.Entry<String, Integer> e : map.entrySet()) {
System.out.println(e.getKey());
System.out.println(e.getValue());
}
//Iteration (2)
Set<String> keys = map.keySet();
for(String key : keys) {
System.out.println(key+ " " + map.get(key));
}
//Removing
map.remove("India");
System.out.println(map);
}
}