The descendingSet() method of java.util.TreeSet<E> class is used to return a reverse order view of the elements contained in this set. The descending set is backed by this set, so changes to the set are reflected in the descending set, and vice-versa. If either set is modified while an iteration over either set is in progress (except through the iterator’s own remove operation), the results of the iteration are undefined.
The returned set has an ordering equivalent to Collections.reverseOrder(comparator()). The expression s.descendingSet().descendingSet() returns a view of s essentially equivalent to s.
public NavigableSet descendingSet()
Return Value: This method returns a reverse order view of this set.
Below are the examples to illustrate the descendingSet() method
TreeSet: [A, B, C, D] Values using DescendingSet: Value : D Value : C Value : B Value : A
Values using DescendingSet: Value : 40 Value : 30 Value : 20 Value : 10
- ConcurrentSkipListSet descendingSet() method in Java
- NavigableSet descendingSet() method in Java
- TreeSet floor() method in Java with Examples
- TreeSet ceiling() method in Java with Examples
- TreeSet higher() method in Java with Examples
- TreeSet descendingIterator() method in Java with Examples
- TreeSet last() Method in Java
- TreeSet contains() Method in Java
- TreeSet first() Method in Java
- TreeSet add() Method in Java
- TreeSet clone() Method in Java
- TreeSet clear() Method in Java
- TreeSet addAll() Method in Java
- TreeSet toArray(T) method in Java with Example
- TreeSet toArray() method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.