-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeMapMethods3.java
119 lines (87 loc) · 3.88 KB
/
TreeMapMethods3.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.util.TreeMap;
import java.util.Map.Entry;
import java.util.Map;
import java.util.Set;
public class TreeMapMethods3 {
public static void main(String[] args) throws Exception {
TreeMap<Float, String> treeMap = new TreeMap<>();
treeMap.put(1.09f, "A");
treeMap.put(2.93f, "B");
treeMap.put(3.98f, "C");
treeMap.put(4.78f, "D");
// ceilingEntry
System.out.println("Ceiling Entry: " + treeMap.ceilingEntry(3.0f));
System.out.println("Ceiling Entry: " + treeMap.ceilingEntry(3.2f));
System.out.println("Ceiling Entry: " + treeMap.ceilingEntry(3.99f));
System.out.println("");
// ceilingKey
System.out.println("Ceiling Key: " + treeMap.ceilingKey(3.0f));
System.out.println("Ceiling Key: " + treeMap.ceilingKey(3.2f));
System.out.println("Ceiling Key: " + treeMap.ceilingKey(3.99f));
System.out.println("");
// descendingKeySet
Set<Float> set = treeMap.descendingKeySet();
System.out.println("Descending Key Set: " + set);
System.out.println("");
// descendingMap
Map<Float, String> Map = treeMap.descendingMap();
System.out.println("Descending Map: " + Map);
// firstEntry
Map.Entry<Float, String> Map1 = treeMap.firstEntry();
System.out.println("First Entry: " + Map1);
// floorEntry
Entry<Float, String> Map2 = treeMap.floorEntry(3.0f);
System.out.println("Floor Entry: " + Map2);
// floorKey
Float Map3floorKey = treeMap.floorKey(3.0f);
System.out.println("Floor Key: " + Map3floorKey);
System.out.println("");
//headMap(K toKey, boolean inclusive)
Map<Float, String> Map4 = treeMap.headMap(3.0f, true);
System.out.println("Head Map: " + Map4);
System.out.println("");
//higherEntry
Entry<Float, String> Map5 = treeMap.higherEntry(4.0f);
System.out.println("Higher Entry: " + Map5);
//higherKey
Float Map6 = treeMap.higherKey(4.0f);
System.out.println("Higher Key: " + Map6);
System.out.println("");
// lastEntry
Entry<Float, String> Map7 = treeMap.lastEntry();
System.out.println("Higher Key: " + Map7);
System.out.println("");
// lowerEntry
Entry<Float, String> Map8 = treeMap.lowerEntry(4.0f);
System.out.println("Lower Entry: " + Map8);
System.out.println("");
Map.Entry<Float, String> Map9 = treeMap.lowerEntry(4.0f);
System.out.println("Lower Entry: " + Map9);
System.out.println("");
//lowerKey
Float Map10 = treeMap.lowerKey(4.0f);
System.out.println("Lower Key: " + Map10);
System.out.println("");
//navigableKeySet
Set<Float> set1 = treeMap.navigableKeySet();
System.out.println("Navigable Key Set: " + set1);
System.out.println("");
//pollFirstEntry
Entry<Float, String> Map11 = treeMap.pollFirstEntry();
System.out.println("Poll First Entry: " + Map11);
System.out.println("");
//pollLastEntry
Entry<Float, String> Map12 = treeMap.pollLastEntry();
System.out.println("Poll Last Entry: " + Map12);
System.out.println("");
// SubMap( fromKey:Key, boolean fromInclusive:true/false, toKey:Key, boolean
// toInclusive:true/false)
Map<Float, String> Map13 = treeMap.subMap(1.0f, true, 4.0f, true);
System.out.println("Sub Map: " + Map13);
System.out.println("");
// tailMap(fromKey :Key, boolean inclusive: true/false)
Map<Float, String> Map14 = treeMap.tailMap(3.0f, true);
System.out.println("Tail Map: " + Map14);
System.out.println("");
}
}