-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path4. Sorted Maps
More file actions
32 lines (25 loc) · 916 Bytes
/
4. Sorted Maps
File metadata and controls
32 lines (25 loc) · 916 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
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
public class App {
public static void main(String[] args) {
Map<Integer, String> hashMap = new HashMap<Integer, String>();
Map<Integer, String> linkedHashMap = new LinkedHashMap<Integer, String>();
Map<Integer, String> treeMap = new TreeMap<Integer, String>();
testMap(treeMap);
}
public static void testMap(Map<Integer, String> map) {
map.put(9, "fox");
map.put(4, "cat");
map.put(8, "dog");
map.put(1, "giraffe");
map.put(0, "swan");
map.put(15, "bear");
map.put(6, "snake");
for(Integer key: map.keySet()) {
String value = map.get(key);
System.out.println(key + ": " + value);
}
}
}