Head Set from TreeSet

 
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {

  public static void main(String[] args) {
    TreeSet<String> tSet = new TreeSet<String>();
    tSet.add("1");
    tSet.add("2");
    tSet.add("3");
    tSet.add("4");
    tSet.add("5");
    SortedSet sortedSet = tSet.headSet("3");
    System.out.println("Head Set Contains : " + sortedSet);
  }
}
  
Home 
  Java Book 
    Runnable examples  

Collection TreeSet:
  1. TreeSet is a sorted set(SortedSet)
  2. First in a TreeSet
  3. Head Set from TreeSet
  4. Higher and lower set
  5. Last from a Set
  6. Reverse order a TreeSet
  7. Tail set, header set and sub set