Get Head Set from TreeSet - Java Collection Framework

Java examples for Collection Framework:TreeSet

Description

Get Head Set from TreeSet

Demo Code

 
import java.util.SortedSet;
import java.util.TreeSet;
 
public class Main {
 
  public static void main(String[] args) {
    TreeSet tSet = new TreeSet();
    tSet.add("1");
    tSet.add("3");
    tSet.add("2");
    tSet.add("5");
    tSet.add("4");
    SortedSet sortedSet = tSet.headSet("3");
   /*  w w w.j a v  a 2  s  .com*/
    System.out.println("Head Set Contains : " + sortedSet);
   
  }
}

Result


Related Tutorials