Skip to content

Commit bff130f

Browse files
Add files via upload
1 parent 179194f commit bff130f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

SortedMap10.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,25 @@ public String toString() {
1616

1717

1818
public static void main(String[] args) throws Exception {
19-
SortedMap<SortedMap10, Integer> map = new TreeMap<>(Comparator.comparingInt(o -> o.a));
19+
SortedMap<SortedMap10, Integer> map = new TreeMap<>(Comparator.comparingInt(o -> o.a+ o.b));
2020
map.put(new SortedMap10(1, 2), 1);
2121
map.put(new SortedMap10(2, 3), 2);
2222
map.put(new SortedMap10(3, 4), 3);
2323
map.put(new SortedMap10(4, 5), 4);
2424
map.put(new SortedMap10(5, 6), 5);
2525
map.put(new SortedMap10(6, 7), 6);
2626
System.out.println("Map:" + map);
27+
28+
SortedMap<SortedMap10, Integer> map1 = new TreeMap<>(Comparator.comparingInt(o -> (o.a + o.b)*(-1)));
29+
30+
map1.put(new SortedMap10(1, 2), 1);
31+
map1.put(new SortedMap10(2, 3), 2);
32+
map1.put(new SortedMap10(3, 4), 3);
33+
map1.put(new SortedMap10(4, 5), 4);
34+
map1.put(new SortedMap10(5, 6), 5);
35+
map1.put(new SortedMap10(6, 7), 6);
36+
System.out.println("Map1:" + map1);
37+
2738

2839
}
2940
}

SortedMap9.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ public static void main(String[] args) throws Exception {
1313
map.put("f", 6);
1414
System.out.println("Map:" + map);
1515

16-
SortedMap<Integer, Integer> map2 = new TreeMap<>(Comparator.comparingInt(o -> o));
16+
SortedMap<Integer, Integer> map2 = new TreeMap<>(Comparator.comparingInt(o -> o*(-1)));
1717
map2.put(1, 1);
1818
map2.put(2, 2);
1919
map2.put(3, 3);
2020
map2.put(4, 4);
2121

2222
System.out.println("Map2:" + map2);
23+
24+
SortedMap<Integer, Integer> map3 = new TreeMap<>(Comparator.comparingInt(o -> o * (1)));
25+
map3.put(1, 1);
26+
map3.put(2, 2);
27+
map3.put(3, 3);
28+
map3.put(4, 4);
29+
30+
System.out.println("Map2:" + map3);
2331

2432
}
2533

0 commit comments

Comments
 (0)