forked from dimpeshmalviya/JavaBasicPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperations.java
More file actions
39 lines (29 loc) · 896 Bytes
/
Operations.java
File metadata and controls
39 lines (29 loc) · 896 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
import java.util.*;
//HashMaps are unordered Map.
public class Operations{
public static void main(String args[]){
//Create
HashMap<String, Integer> hm = new HashMap<>();
//Insert
hm.put("India", 100);
hm.put("US", 50);
hm.put("China", 150);
System.out.println(hm);
//Get
int population = hm.get("India");
System.out.println(population);
System.out.println(hm.get("Nepal")); // this will print null
//ContainsKey
System.out.println(hm.containsKey("India"));
System.out.println(hm.containsKey("Indonasia"));
//remove
hm.remove("China");
System.out.println(hm);
//Size
System.out.println(hm.size());
//isEmpty
// Clear function ->
hm.clear();
System.out.println(hm.isEmpty());
}
}