The descendingIterator() method of NavigableSet interface in Java is used to return an iterator over the elements in this set, in descending order. This iterator can be then used to iterate over the elements of the set.
The iterator returned by this set is also equivalent to descendingSet().iterator().
Where, E is the type of elements maintained by this Set container.
Parameters: This function does not accepts any parameter.
Return Value: It returns an iterator over the set of elements contained in this set container in descending order.
Below programs illustrate the descendingIterator() method in Java:
Program 1: NavigableSet with integer elements.
Value: 6 Value: 5 Value: 4 Value: 3 Value: 2 Value: 1 Value: 0
Program 2: NavigableSet with string elements.
Value: G Value: F Value: E Value: D Value: C Value: B Value: A
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.