File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments