Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get navigable key set in java from NavigableMap
The navigableKeySet() method is used to get view of the Map from NavigableMap.
Let us first create a NavigableMap
NavigableMap<String, Integer> n = new TreeMap<String, Integer>();
Add some elements in the NavigableMap
n.put("A", 498);
n.put("B", 389);
n.put("C", 868);
n.put("D", 988);
n.put("E", 686);
n.put("F", 888);
n.put("G", 999);
n.put("H", 444);
n.put("I", 555);
n.put("J", 666);
Get Navigable Key Set now
n.navigableKeySet()
The following is an example to get navigable key set
Example
import java.util.ArrayList;
import java.util.*;
public class Demo {
public static void main(String[] args) {
NavigableMap<String, Integer> n =
new TreeMap<String, Integer>();
n.put("A", 498);
n.put("B", 389);
n.put("C", 868);
n.put("D", 988);
n.put("E", 686);
n.put("F", 888);
n.put("G", 999);
n.put("H", 444);
n.put("I", 555);
n.put("J", 666);
System.out.println("NavigableMap elements...\n"+n);
System.out.println("Navigable Key Set = "+n.navigableKeySet());
}
}
Output
NavigableMap elements...
{A=498, B=389, C=868, D=988, E=686, F=888, G=999, H=444, I=555, J=666}
Navigable Key Set = [A, B, C, D, E, F, G, H, I, J]Advertisements