Open In App

TreeSet descendingIterator() method in Java with Examples

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
2 Likes
Like
Report

The descendingIterator() method of java.util.TreeSet<E> class is used to return an iterator over the elements in this set in descending order.
Syntax: 
 

public Iterator descendingIterator()


Return Value: This method returns an iterator over the elements in this set in descending order.
Below are the examples to illustrate the descendingIterator() method
Example 1: 
 


Output
TreeSet: [10, 20, 30, 40]

Values using DescendingIterator:
Value : 40
Value : 30
Value : 20
Value : 10

Example 2: 
 


Output
TreeSet: [A, B, C, D]

Values using DescendingIterator:
Value : D
Value : C
Value : B
Value : A

Next Article

Similar Reads