SortedSet subSet(Object from, Object to) Returns a sorted set containing this set's elements from from through to. : SortedSet « Utility Classes « SCJP






import java.util.Iterator;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

public class MainClass {
  public static void main(String[] argv) {
    Set set = new TreeSet();
    set.add("1");
    set.add("2");
    set.add("3");

    Iterator it = set.iterator();
    while (it.hasNext()) {
      System.out.println(it.next());
    }

    SortedSet sortedSet = (SortedSet) set;

    System.out.println(sortedSet.subSet("2", "3"));
  }
}
1
2
3
[2]








8.18.SortedSet
8.18.1.SortedSet: Object first() Returns this set's first element.
8.18.2.SortedSet: Object last() Returns this set's last element.
8.18.3.SortedSet headSet(Object thru) Returns a sorted set containing this set's elements through the specified element.
8.18.4.SortedSet tailSet(Object from) Returns a sorted set containing this set's elements from the specified element through the end.
8.18.5.SortedSet subSet(Object from, Object to) Returns a sorted set containing this set's elements from from through to.