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

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Utility Classes » SortedSet 
8.18.5.SortedSet subSet(Object from, Object to) Returns a sorted set containing this set's elements from from through to.
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 = (SortedSetset;

    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.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.