-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapEntry_ConcurrentSkipListMap.java
75 lines (63 loc) · 2.66 KB
/
MapEntry_ConcurrentSkipListMap.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentSkipListMap;
public class MapEntry_ConcurrentSkipListMap {
//Map.Entry
public static void main(String[] args) throws Exception {
ConcurrentSkipListMap<String, String> map = new ConcurrentSkipListMap<>();
map.put("1", "one");
map.put("2", "two");
map.put("3", "three");
map.put("4", "four");
map.put("5", "five");
map.put("6", "six");
map.put("7", "seven");
map.put("8", "eight");
map.put("9", "nine");
map.put("10", "ten");
System.out.println("Map:" + map);
System.out.println(" ");
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("Key:" + entry.getKey() + " Value:" + entry.getValue());
}
Set<Map.Entry<String, String>> entries = map.entrySet();
System.out.println("Entry Set:" + entries);
System.out.println(" ");
for (Entry<String, String> entry : map.entrySet()) {
System.out.println("Key:" + entry.getKey() + " Value:" + entry.getValue());
}
Set<Entry<String, String>> entries1 = map.entrySet();
System.out.println("Entry Set:" + entries1);
// higherEntry(K key)
Entry<String, String> entry4 = map.higherEntry("3");
System.out.println("higherEntry:" + entry4);
// lowerEntry(K key)
Entry<String, String> entry5 = map.lowerEntry("3");
System.out.println("lowerEntry:" + entry5);
System.out.println(" ");
// ceilingEntry(K key)
Entry<String, String> entry6 = map.ceilingEntry("3");
System.out.println("ceilingEntry:" + entry6);
// floorEntry(K key)
Entry<String, String> entry7 = map.floorEntry("3");
System.out.println("floorEntry:" + entry7);
System.out.println(" ");
// firstEntry()
Entry<String, String> entry8 = map.firstEntry();
System.out.println("firstEntry:" + entry8);
System.out.println(" ");
// lastEntry()
Entry<String, String> entry9 = map.lastEntry();
System.out.println("lastEntry:" + entry9);
System.out.println(" ");
// pollFirstEntry()
Entry<String, String> entry10 = map.pollFirstEntry();
System.out.println("pollFirstEntry:" + entry10);
System.out.println(" ");
// pollLastEntry()
Entry<String, String> entry11 = map.pollLastEntry();
System.out.println("pollLastEntry:" + entry11);
System.out.println(" ");
}
}