VOOZH about

URL: https://www.geeksforgeeks.org/java/treeset-descendingiterator-method-in-java-with-examples/

⇱ TreeSet descendingIterator() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TreeSet descendingIterator() method in Java with Examples

Last Updated : 11 Jul, 2025

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
Comment