TreeSet descendingSet Example
TreeSet class descendingSet example. This example shows you how to use descendingSet method.
TreeSet class descendingSet example.public NavigableSet descendingSet() Returns 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.
Here is the code
/**
* @ # DescendingSet.java
* A class repersenting use to descendingSet method
* of TreeSet class in java.util package
* version 23 May 2008
* author Rose India
*/
import java.util.*;
public class DescendingSet {
public static void main(String args[]) {
// Create a new TreeSet object:
TreeSet treeset = new TreeSet();
// Create new element object and Add the elementreeset to the set:
treeset.add(new Integer(2));
treeset.add(new Integer(5));
treeset.add(new Integer(7));
System.out.println("treeset = " + treeset);
NavigableSet nset=treeset.descendingSet();
System.out.println(nset.ceiling(3));
}
} |
|