Skip to content

Commit 7990548

Browse files
Create NavigableMapDemo.java
1 parent 04211ca commit 7990548

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package learnCollections;
2+
3+
import java.util.NavigableMap;
4+
import java.util.TreeMap;
5+
6+
/*
7+
+----------------------+
8+
| SortedMap |
9+
| (interface) |
10+
+----------------------+
11+
^
12+
|
13+
| extends
14+
|
15+
+----------------------+
16+
| NavigableMap |
17+
| (interface) |
18+
+----------------------+
19+
^
20+
|
21+
| implements
22+
|
23+
+----------------------+
24+
| TreeMap |
25+
| (class) |
26+
+----------------------+
27+
28+
*/
29+
30+
public class NavigableMapDemo {
31+
public static void main(String[] args) {
32+
NavigableMap<Integer, String> navigableMap = new TreeMap<>();
33+
navigableMap.put(1, "One");
34+
navigableMap.put(5, "Five");
35+
navigableMap.put(3, "Three");
36+
37+
System.out.println(navigableMap); // {1=One, 3=Three, 5=Five}
38+
39+
System.out.println(navigableMap.lowerKey(4)); // returns the greatest key strictly < given key or null if there is no such key
40+
System.out.println(navigableMap.ceilingKey(4)); // returns the least key >= given key or null if there is no such key
41+
System.out.println(navigableMap.higherEntry(1)); // returns the least entry > given key or null if there is no such key
42+
System.out.println(navigableMap.floorEntry(2)); // returns the greatest entry <= given key or null if there is no such key
43+
System.out.println(navigableMap.descendingMap()); // returns a reverse order view of the mappings contained in this map
44+
}
45+
}

0 commit comments

Comments
 (0)