Skip to content

Commit e345b55

Browse files
Add files via upload
1 parent 22372b3 commit e345b55

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import java.util.concurrent.ConcurrentSkipListMap;
2+
import java.util.Comparator;
3+
public class constructConcurrentSkipListMap5 {
4+
public static Comparator<Integer> valueComparator = new Comparator<>() {
5+
@Override
6+
public int compare(Integer a, Integer b) {
7+
return b.compareTo(a);
8+
}
9+
};
10+
11+
public static void main(String[] args) {
12+
// ConcurrentSkipListMap​(Comparator<? super K> comparator)
13+
ConcurrentSkipListMap<Integer, String> map = new ConcurrentSkipListMap<>(valueComparator);
14+
map.put(1, "one");
15+
map.put(2, "two");
16+
map.put(3, "three");
17+
map.put(4, "four");
18+
map.put(5, "five");
19+
map.put(6, "six");
20+
map.put(7, "seven");
21+
map.put(8, "eight");
22+
map.put(9, "nine");
23+
map.put(10, "ten");
24+
System.out.println("Map:" + map);
25+
26+
ConcurrentSkipListMap<Integer, String> map1 = new ConcurrentSkipListMap<>(valueComparator.reversed());
27+
28+
map1.put(1, "one");
29+
map1.put(2, "two");
30+
map1.put(3, "three");
31+
map1.put(4, "four");
32+
map1.put(5, "five");
33+
34+
System.out.println("Map1:" + map1);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)