Sunday, March 13, 2011

The SortedSet interface

A SortedSet(in the API reference documentation)is a Set(in the API reference documentation)that maintains its elements in ascending order, sorted according to the elements' natural order, or according to a Comparator provided at SortedSet creation time. (Natural order and Comparators are discussed in the previous section, on Object Ordering.) In addition to the normal Set operations, the Set interface provides operations for:
  • Range-view: Performs arbitrary range operations on the sorted set.
  • Endpoints: Returns the first or last element in the sorted set.
  • Comparator access: Returns the Comparator used to sort the set (if any).

The SortedSet interface is shown below:

public interface SortedSet extends Set {
// Range-view
SortedSet subSet(Object fromElement, Object toElement);
SortedSet headSet(Object toElement);
SortedSet tailSet(Object fromElement);
// Endpoints
Object first();
Object last();
// Comparator access
Comparator comparator();

SortedSet Operations 

Standard Constructors 

Range-view Operations on SortedSet

Example – Creating a SortedSet


No comments:

Post a Comment