Get Sub Set from TreeSet - Java Collection Framework

Java examples for Collection Framework:TreeSet

Description

Get Sub Set from TreeSet

Demo Code


import java.util.TreeSet;
import java.util.SortedSet;
 
public class Main {
 
  public static void main(String[] args) {
    TreeSet tSet = new TreeSet();
   //from   w  w w .  j  av  a 2 s  .  c o m
    tSet.add("1");
    tSet.add("3");
    tSet.add("2");
    tSet.add("5");
    tSet.add("4");
 
    SortedSet sortedSet = tSet.subSet("2","5");
    System.out.println("SortedSet Contains : " + sortedSet);
  }
}

Result


Related Tutorials