TreeSet tailSet Example
TreeSet class tailSet example. This example shows you how to use tailSet method.
TreeSet class tailSet example. public NavigableSet tailSet(Object,boolean) Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement.
Here is the code
/**
* @ # TailSet.java
* A class repersenting use to TailSet method
* of TreeSet class in java.util package
* version 23 May 2008
* author Rose India
*/
import java.util.*;
public class TailSet1 {
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);
SortedSet ss = treeset.tailSet(2, true);
System.out.println("Tailset : " + ss);
ss = treeset.tailSet(2, false);
System.out.println("Tailset : " + ss);
}
} |
Output
treeset = [2, 5, 7]
Tailset : [2, 5, 7]
Tailset : [5, 7] |
|