Java TreeSet get sub set by value range

Description

Java TreeSet get sub set by value range

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");
    //  www.  j a  v a 2 s .c om
    SortedSet<String> sortedSet = tSet.subSet("2", "5");

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



PreviousNext

Related