
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
NavigableMap Interface in Java with Example
NavigableMap is an extension of the SortedMap collection framework. It is used to arrange the elements in a uniform fashion. NavigableMap has different methods to iterate over the elements in the Map.
Example
Following is an example −
import java.util.NavigableMap; import java.util.TreeMap; public class Demo { public static void main(String[] args) { NavigableMap<String, Integer> my_map = new TreeMap<String, Integer>(); my_map.put("A", 856); my_map.put("M", 349); my_map.put("Z", 567); System.out.printf("The descending set is : %s%n", my_map.descendingKeySet()); System.out.printf("The floor entry is : %s%n", my_map.floorEntry("A")); System.out.printf("The first key : %s%n", my_map.firstKey()); System.out.printf("The reversed map : %s%n", my_map.descendingMap()); } }
Output
The descending set is : [Z, M, A] The floor entry is : A=856 The first key : A The reversed map : {Z=567, M=349, A=856}
A class named Demo contains the main function. An instance of the NavigableMap is created, and elements are added to the map with the help of the ‘put’ function. The relevant function are used to display the map in descending order, the first element of the map, the first key of the map, and the reversed version of the map.
Advertisements