-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMapTest.java
More file actions
37 lines (26 loc) · 859 Bytes
/
HashMapTest.java
File metadata and controls
37 lines (26 loc) · 859 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
package datastructure.hashmap;
import java.util.*;
public class HashMapTest {
public static void main(String[] args) {
HashMap<Integer, String> hm = new HashMap<Integer, String>();
hm.put(3, "pen");
hm.put(1, "watch");
hm.put(5, "paper");
hm.put(4, "monitor");
hm.put(2, "keyboard");
// Find all the values
Collection<String> productVal = hm.values();
Iterator<String> it = productVal.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
List<Integer> list = new ArrayList<Integer>(hm.keySet());
Collections.sort(list);
LinkedHashMap<Integer, String> linkeHashMap = new LinkedHashMap<Integer, String>();
for (Integer i : list) {
linkeHashMap.put(i, hm.get(i));
}
System.out.println(linkeHashMap);
System.out.println(linkeHashMap.containsValue("pen"));
} // end of main
} // end of HashMap