TreeSet.tailSet(E fromElement, boolean inclusive) has the following syntax.
public NavigableSet <E> tailSet(E fromElement, boolean inclusive)
In the following code shows how to use TreeSet.tailSet(E fromElement, boolean inclusive) method.
import java.util.TreeSet; import java.util.Iterator; /*from w ww .j a v a 2 s. c o m*/ public class Main { public static void main(String[] args) { TreeSet <Integer> treeadd = new TreeSet<Integer> (); treeadd.add(1); treeadd.add(2); treeadd.add(3); treeadd.add(4); treeadd.add(5); treeadd.add(6); treeadd.add(7); treeadd.add(8); TreeSet <Integer> treetailsetincl=(TreeSet<Integer>)treeadd.tailSet(5, true); Iterator<Integer> iterator = treetailsetincl.iterator(); while (iterator.hasNext()){ System.out.println(iterator.next()); } } }
The code above generates the following result.