-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashing2.java
42 lines (39 loc) · 1.24 KB
/
Hashing2.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
import java.util.*;
public class Hashing2 {
public static void main(String[] args) {
HashMap<String, Integer> map = new HashMap<>();
map.put("India", 180);
map.put("China", 150);
map.put("USA", 120);
System.out.println(map);
if (map.containsKey("Indonesia")) {
System.out.println("Contains");
} else {
System.out.println("Does Not contain");
}
map.put("India", 130);
System.out.println(map.get("India"));
System.out.println(map.get("Indonesia"));
/*
* int[] arr = { 12, 15, 18, 20 };
* for (int i = 0; i < arr.length; i++) {
* if (arr[i] == 15) {
* System.out.println(i);
* }
* }
* for (int val : arr) {
* System.out.println(val);
* }
*/
System.out.println(" ");
for (Map.Entry<String, Integer> e : map.entrySet()) {
System.out.println(e.getKey());
System.out.println(e.getValue());
}
map.remove("China");
Set<String> keys = map.keySet();
for (String key : keys) {
System.out.println(key + " " + map.get(key));
}
}
}