-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNavigableMapDemo.java
More file actions
45 lines (39 loc) · 1.69 KB
/
NavigableMapDemo.java
File metadata and controls
45 lines (39 loc) · 1.69 KB
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
package learnCollections;
import java.util.NavigableMap;
import java.util.TreeMap;
/*
+----------------------+
| SortedMap |
| (interface) |
+----------------------+
^
|
| extends
|
+----------------------+
| NavigableMap |
| (interface) |
+----------------------+
^
|
| implements
|
+----------------------+
| TreeMap |
| (class) |
+----------------------+
*/
public class NavigableMapDemo {
public static void main(String[] args) {
NavigableMap<Integer, String> navigableMap = new TreeMap<>();
navigableMap.put(1, "One");
navigableMap.put(5, "Five");
navigableMap.put(3, "Three");
System.out.println(navigableMap); // {1=One, 3=Three, 5=Five}
System.out.println(navigableMap.lowerKey(4)); // returns the greatest key strictly < given key or null if there is no such key
System.out.println(navigableMap.ceilingKey(4)); // returns the least key >= given key or null if there is no such key
System.out.println(navigableMap.higherEntry(1)); // returns the least entry > given key or null if there is no such key
System.out.println(navigableMap.floorEntry(2)); // returns the greatest entry <= given key or null if there is no such key
System.out.println(navigableMap.descendingMap()); // returns a reverse order view of the mappings contained in this map
}
}