|
| 1 | +import java.util.concurrent.ConcurrentSkipListMap; |
| 2 | +import java.util.Comparator; |
| 3 | + class constructConcurrentSkipListMap6 { |
| 4 | + |
| 5 | + int a; |
| 6 | + int b; |
| 7 | + |
| 8 | + public constructConcurrentSkipListMap6(int a, int b) { |
| 9 | + this.a = a; |
| 10 | + this.b = b; |
| 11 | + } |
| 12 | + |
| 13 | + public String toString() { |
| 14 | + return "a:" + a + " b:" + b; |
| 15 | + } |
| 16 | + |
| 17 | + public static void main(String[] args) throws Exception { |
| 18 | + // ConcurrentSkipListMap(Comparator<? super K> comparator) |
| 19 | + ConcurrentSkipListMap<String, String> map = new ConcurrentSkipListMap<>(Comparator.reverseOrder()); |
| 20 | + map.put("1", "one"); |
| 21 | + map.put("2", "two"); |
| 22 | + map.put("3", "three"); |
| 23 | + map.put("4", "four"); |
| 24 | + map.put("5", "five"); |
| 25 | + System.out.println("Map:"+map); |
| 26 | + |
| 27 | + |
| 28 | + ConcurrentSkipListMap<String, String> map2 = new ConcurrentSkipListMap<>(Comparator.naturalOrder()); |
| 29 | + map2.put("1", "one"); |
| 30 | + map2.put("2", "two"); |
| 31 | + map2.put("3", "three"); |
| 32 | + map2.put("4", "four"); |
| 33 | + map2.put("5", "five"); |
| 34 | + System.out.println("Map:"+map2); |
| 35 | + |
| 36 | + |
| 37 | + ConcurrentSkipListMap<Integer,Integer> map3 = new ConcurrentSkipListMap<>(Comparator.comparingInt(o -> o*(-1))); |
| 38 | + |
| 39 | + map3.put(1, 1); |
| 40 | + map3.put(2, 2); |
| 41 | + map3.put(3, 3); |
| 42 | + map3.put(4, 4); |
| 43 | + map3.put(5, 5); |
| 44 | + System.out.println("Map:"+map3); |
| 45 | + |
| 46 | + |
| 47 | + ConcurrentSkipListMap<constructConcurrentSkipListMap6, Integer> map4 = new ConcurrentSkipListMap<>( |
| 48 | + Comparator.comparingInt(o -> (o.a+o.b)*(-1))); |
| 49 | + |
| 50 | + map4.put(new constructConcurrentSkipListMap6(1, 1), 1); |
| 51 | + map4.put(new constructConcurrentSkipListMap6(2, 2), 2); |
| 52 | + map4.put(new constructConcurrentSkipListMap6(3, 3), 3); |
| 53 | + map4.put(new constructConcurrentSkipListMap6(4, 4), 4); |
| 54 | + map4.put(new constructConcurrentSkipListMap6(5, 5), 5); |
| 55 | + System.out.println("Map:"+map4); |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments