-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMapDemo.java
More file actions
52 lines (37 loc) · 1.03 KB
/
HashMapDemo.java
File metadata and controls
52 lines (37 loc) · 1.03 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
42
43
44
45
46
47
48
49
50
51
52
package Others;
import java.util.HashMap;
public class HashMapDemo {
public static void main(String[] args) {
HashMap<Integer, String> items = new HashMap<>();
items.put(101, "Saon");
items.put(102, "Srabon");
items.put(103, "Sikder");
// to get specific item
System.out.println("Speciifc item: " + items.get(102));
// to get all
System.out.println("All items: " + items);
// clone items
items.clone();
System.out.println("Clone item: " + items);
// to get keys
for (int i : items.keySet()) {
System.out.print(i+" ");
}
System.out.println();
// to get values
for (String i : items.values()) {
System.out.print(i+" ");
}
System.out.println();
// to get both
for(int i : items.keySet()) {
System.out.println("key: " + i + " value: " + items.get(i));
}
// remove item
items.remove(101);
System.out.println("Remove Speciifc item: " + items);
// remove all
items.clear();
System.out.println("Remove all items: " + items);
}
}