Java TreeSet descendingSet() Method
Example
Print a sorted set in reverse order:
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
TreeSet<String> cars = new TreeSet<String>();
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");
cars.add("Mazda");
System.out.println(cars.descendingSet());
}
}
Definition and Usage
The descendingSet() method returns the items of the set in reverse (descending) order, from the last (highest) item to the first (lowest) item.
The returned set is a view of the original set (it shows the same items, it is not a copy). If you change one of them, the other one changes too.
Syntax
public NavigableSet<T> descendingSet()
T refers to the data type of items in the set.
Parameter Values
None.
Technical Details
| Returns: | A set with the same items, in reverse order. |
|---|
Related Pages
❮ TreeSet Methods