NavigableSet descendingSet() method in Java
The descendingSet() method of NavigableSet interface in Java is used to return a reverse order view of the elements contained in this set. The descending set is backed by this set, so any changes to the set are reflected in the descending set, and vice-versa. If any of the set is modified while an iteration over other set is in progress, the results of the iteration are undefined.
Where, E is the type of elements maintained by this Set container.
Parameters: This function does not accepts any parameter.
Return Value: It returns a reverse order view of the elements contained in this set.
Below programs illustrate the descendingSet() 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
Please Login to comment...