-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSortedMap9.java
34 lines (27 loc) · 981 Bytes
/
SortedMap9.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
import java.util.Comparator;
import java.util.SortedMap;
import java.util.TreeMap;
public class SortedMap9 {
public static void main(String[] args) throws Exception {
SortedMap<String, Integer> map = new TreeMap<>(Comparator.reverseOrder());
map.put("a", 1);
map.put("b", 2);
map.put("c", 3);
map.put("d", 4);
map.put("e", 5);
map.put("f", 6);
System.out.println("Map:" + map);
SortedMap<Integer, Integer> map2 = new TreeMap<>(Comparator.comparingInt(o -> o*(-1)));
map2.put(1, 1);
map2.put(2, 2);
map2.put(3, 3);
map2.put(4, 4);
System.out.println("Map2:" + map2);
SortedMap<Integer, Integer> map3 = new TreeMap<>(Comparator.comparingInt(o -> o * (1)));
map3.put(1, 1);
map3.put(2, 2);
map3.put(3, 3);
map3.put(4, 4);
System.out.println("Map2:" + map3);
}
}