E
- the type of elements in this listpublic interface OrderedList<E extends Comparable<E>>
extends Cloneable
compareTo()
method
defined in the elements' class).
The user can access elements by their integer index (position in
the list), and search for elements in the list.The lists implementing this interface allow duplicate elements. They do not allow null elements.
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
Adds the specified element to this list in a sorted order.
|
void |
clear()
Removes all of the elements from this list.
|
Object |
clone()
Returns a shallow copy of this list.
|
boolean |
contains(Object o)
Returns true if this list contains the specified element.
|
boolean |
equals(Object o)
Compares the specified object with this list for equality.
|
E |
get(int index)
Returns the element at the specified position in this list.
|
int |
indexOf(Object o)
Returns the index of the first occurrence of the specified element
in this list, or -1 if this list does not contain the element.
|
E |
remove(int index)
Removes the element at the specified position in this list.
|
boolean |
remove(Object o)
Removes the first occurrence of the specified element from this list,
if it is present.
|
int |
size()
Returns the number of elements in this list.
|
String |
toString()
Returns a string representation of this list.
|
boolean add(E e)
The element added must implement Comparable
e
- element to be appended to this listClassCastException
- if the class of the specified element
does not implement ComparableNullPointerException
- if the specified element is nullvoid clear()
Object clone()
CloneNotSupportedException
- if the object's class does
not support the Cloneable interfaceboolean contains(Object o)
o
- element whose presence in this list is to be testedClassCastException
- if the type of the specified element
is incompatible with this listNullPointerException
- if the specified element is nullboolean equals(Object o)
true
if and only if the specified object is also a list, both
lists have the same size, and all corresponding pairs of elements in
the two lists are equal. (Two elements e1
and
e2
are equal if e1.equals(e2)
.)
In other words, two lists are defined to be
equal if they contain the same elements in the same order.equals
in class Object
o
- the object to be compared for equality with this listtrue
if the specified object is equal to this listE get(int index)
index
- index of the element to returnIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())int indexOf(Object o)
o
- element to search forE remove(int index)
index
- the index of the element to be removedIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())boolean remove(Object o)
i
such that
(o.equals(get(i))
(if such an element exists). Returns true
if this list
contained the specified element (or equivalently, if this list
changed as a result of the call).o
- element to be removed from this list, if presenttrue
if this list contained the specified elementClassCastException
- if the type of the specified element
is incompatible with this listNullPointerException
- if the specified element is null and this
list does not permit null elementsint size()
String toString()
toString()
method of those elements.toString
in class Object