-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathHashMapInJava.java
More file actions
33 lines (26 loc) · 865 Bytes
/
HashMapInJava.java
File metadata and controls
33 lines (26 loc) · 865 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
import java.util.*;
public class HashMapInJava {
public static void main(String[] args) {
HashMap<String,Integer> map = new HashMap<>();
//insert
map.put("India", 01);
map.put("Pakistan", 02);
map.put("England", 03);
map.put("Austrelia", 04);
map.put("South Africa", 05);
System.out.println(map);
//search
if(map.containsKey("India")){
System.out.println("Key Present");
}
// System.out.println(map.get("India"));
//Print Key and Value using for loop
for(Map.Entry<String,Integer> e:map.entrySet()){
System.out.println(e.getKey());
System.out.println(e.getValue());
}
// Remove a value from HashMap
map.remove("Pakistan");
System.out.println(map);
}
}