SortedSetE


SortedSet<E> java.util

Java 1.2 collection

This interface is a Set that sorts its elements and guarantees that its iterator( ) method returns an Iterator that enumerates the elements of the set in sorted order. As with the Set interface, it is conventional for all implementations of SortedSet to provide a no-argument constructor that creates an empty set and a copy constructor that expects a Collection object specifying the initial (unsorted) contents of the set. Furthermore, when creating a SortedSet , there should be a way to specify a Comparator object that compares and sorts the elements of the set. If no Comparator is specified, the elements of the set must all implement java.lang.Comparable so they can be sorted in their natural order. See also Set , treeSet , and SortedMap .

SortedSet defines a few methods in addition to those it inherits from the Set interface. first( ) and last( ) return the lowest and highest objects in the set. headSet( ) returns all elements from the beginning of the set up to (but not including) the specified element. tailSet( ) returns all elements between (and including) the specified element and the end of the set. subSet( ) returns all elements of the set from (and including) the first specified element up to (but excluding) the second specified element. Note that all three methods return a SortedSet that is implemented as a view onto the original SortedSet . Changes in the original set are visible through the returned set and vice versa.

Figure 16-57. java.util.SortedSet<E>

 public interface  SortedSet<E>  extends Set<E> {  // Public Instance Methods  Comparator<? super E>  comparator  ( );        E  first  ( );        SortedSet<E>  headSet  (E  toElement  );        E  last  ( );        SortedSet<E>  subSet  (E  fromElement  , E  toElement  );        SortedSet<E>  tailSet  (E  fromElement  );   } 

Implementations

treeSet

Passed To

Collections.{checkedSortedSet( ) , synchronizedSortedSet( ) , unmodifiableSortedSet( )} , PriorityQueue.PriorityQueue( ) , treeSet.TreeSet( )

Returned By

Collections.{checkedSortedSet( ) , synchronizedSortedSet( ) , unmodifiableSortedSet( )} , treeSet.{headSet( ) , subSet( ) , tailSet( )}



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net