VOOZH about

URL: https://www.geeksforgeeks.org/java/treemap-descendingkeyset-method-in-java-with-examples/

⇱ TreeMap descendingKeySet() Method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TreeMap descendingKeySet() Method in Java with Examples

Last Updated : 16 Nov, 2022

The descendingKeySet() method of TreeMap class returns a reverse order NavigableSet view of the keys contained within the map. The iterator of the set returns the keys in descending order. 

Note: The set is backed by the map, so changes to the map are reflected within the set, and vice-versa.

Syntax:

public NavigableSet<K> descendingKeySet()

Parameters: The method does not take any parameters.
Return Value: The method returns a navigable set view of the values contained in the map.

Exception: The method does not throw any exceptions.

Example 1: 
 

Output: 

Navigable set values are: [7, 6, 3, 2, 1, 0]


Example 2: 
 

Output: 
 

TreeMap values :- {1=Guru, 2=Ayush, 3=Devesh, 4=Kashish}
Reverse key values:- [4, 3, 2, 1]


 

Comment