Methods in the SortedCollection Interface

Some methods may not be implemented. Follow this link for details.

 

SortedCollection Interface

boolean

add (Object item)

Adds an item to this sorted collection in the last possible position while still retaining the collection's sorted character.  Throws an exception if the item is non-comparable, else returns true.

boolean

addUnique (Object item)

Adds an item to this sorted collection provided the item is not equal to one already in this collection.  Returns true if the collection changes.  Throws an exception if the item is non-comparable.

void

clear ()

Removes all items from this sorted collection.

Object

clone ()

Returns a shallow copy of this sorted collection.

Collection

collectionView ()

Returns a collection view of the items contained in this sorted collection.

boolean

contains (Object item)

Returns true if this sorted collection contains an item equal to the specified item.  Throws an exception if the item is non-comparable.

boolean

equals (Object other)

Returns true if the other object is a sorted collection that equals this sorted collection.  Two sorted collections are considered equal if their items are equal when taken in ascending order.

int

indexOf (Object item)

Returns the index of the first item equal to the specified item or -1 if there is none.  Throws an exception if the specified item is non-comparable.

Object

get (int i)

Returns the ith item in this collection.  Throws an exception if the index i is out of the range 0 to size - 1.

Object

get (Object item)

Returns the first item equal to the specified item or null if there is none.  Throws an exception if the specified item is non-comparable.

int

hashCode ()

Returns the hash code value for this sorted collection.

boolean

isEmpty ()

Returns true if this sorted collections contains no elements.

Iterator

iterator ()

Returns an iterator over the items contained in this sorted collection.  The iterator provides the items sorted in ascending order.  The iterator could support removal, depending on the implementation.

Object

remove (int i)

Removes and returns the ith item in this collection.  Throws an exception if the index i is out of the range 0 to size - 1.

boolean

remove (Object item)

Removes the first item equal to the specified item from the collection.  Returns true if the collection changes.  Throws an exception if the item is non-comparable.

int

size ()

Returns the number of items in this sorted collection.

Object[ ]

toArray ()

Returns an array containing all the items in this sorted collection.  The array is sorted in ascending order.

String

toString ()

Returns a string that lists the items in this collection sorted in ascending order.

 

 

martin@cc.wwu.edu
Disclaimer

Copyright Martin Osborne 1998-2001
  All rights reserved