-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashing.java
More file actions
41 lines (33 loc) · 979 Bytes
/
Hashing.java
File metadata and controls
41 lines (33 loc) · 979 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
import java.util.*;
public class Hashing {
public static void main(String args[]){
HashMap<String, Integer> map = new HashMap<>();
//Insertion
map.put("India", 120);
map.put("USA", 30);
map.put("China", 150);
System.out.println(map);
//Search
if(map.containsKey("China")){
System.out.println("key found");
}
else{
System.out.println("key not found");
}
//Getting key
System.out.println(map.get("India"));
System.out.println(map.get("Pakistan"));
//Iterations
for(Map.Entry<String, Integer> e: map.entrySet()){
System.out.println(e.getKey());
System.out.println(e.getValue());
}
//Iteration using keys
Set<String> keys = map.keySet();
for(String key : keys){
System.out.println(key+" "+ map.get(key));
}
//Remove
map.remove("China");
}
}