Get Sub Set from TreeSet in Java

Description

The following code shows how to get Sub Set from TreeSet.

Example


/*from  w  w w.  ja v  a 2 s  . c  o  m*/
import java.util.TreeSet;

import java.util.SortedSet;

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.subSet("2", "5");

    System.out.println("SortedSet Contains : " + sortedSet);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Collection »




Java ArrayList
Java Collection
Java Comparable
Java Comparator
Java HashMap
Java HashSet
Java Iterator
Java LinkedHashMap
Java LinkedHashSet
Java LinkedList
Java List
Java ListIterator
Java Map
Queue
Java Set
Stack
Java TreeMap
TreeSet