Java TreeSet.tailSet(E fromElement)

Syntax

TreeSet.tailSet(E fromElement) has the following syntax.

public SortedSet <E> tailSet(E fromElement)

Example

In the following code shows how to use TreeSet.tailSet(E fromElement) method.


//w ww.ja  va  2s. c  o m

import java.util.TreeSet;
import java.util.Iterator;

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> treetailset=(TreeSet<Integer>)treeadd.tailSet(4); 
      
      Iterator<Integer> iterator = treetailset.iterator();
        
      while (iterator.hasNext()){
         System.out.println(iterator.next());
      }
   }     
}

The code above generates the following result.