java.util
public
interface
java.util.List<E>
List is a collection which maintains an ordering for its elements. Every
element in the list has an index.
Known Indirect Subclasses
AbstractList<E> |
AbstractList is an abstract implementation of the List interface, optimized
for a backing store which supports random access. |
AbstractSequentialList<E> |
AbstractSequentialList is an abstract implementation of the List interface. |
ArrayList<E> |
ArrayList is an implementation of List, backed by an array. |
CopyOnWriteArrayList<E> |
Implements a ArrayList variant that is thread-safe. |
LinkedList<E> |
LinkedList is an implementation of List, backed by a linked list. |
Stack<E> |
Stack is a Last-In/First-Out(LIFO) data structure which
represents a stack of objects. |
Vector<E> |
Vector is a variable size contiguous indexable array of Objects. |
Summary
Public Methods
add,
addAll,
clear,
contains,
containsAll,
equals,
hashCode,
isEmpty,
iterator,
remove,
removeAll,
retainAll,
size,
toArray,
toArray
Details
Public Methods
public
void
add(int location, E object)
Inserts the specified object into this Vector at the specified location.
The object is inserted before any previous element at the specified
location. If the location is equal to the size of this List, the object
is added at the end.
Parameters
location
| the index at which to insert |
object
| the object to add |
public
boolean
add(E object)
Adds the specified object at the end of this List.
public
boolean
addAll(int location, Collection<? extends E> collection)
Inserts the objects in the specified Collection at the specified location
in this List. The objects are added in the order they are returned from
the Collection iterator.
Parameters
location
| the index at which to insert |
collection
| the Collection of objects |
Returns
- true if this List is modified, false otherwise
public
boolean
addAll(Collection<? extends E> collection)
Adds the objects in the specified Collection to the end of this List. The
objects are added in the order they are returned from the Collection
iterator.
Parameters
collection
| the Collection of objects |
Returns
- true if this List is modified, false otherwise
public
void
clear()
Removes all elements from this List, leaving it empty.
public
boolean
contains(Object object)
Searches this List for the specified object.
Parameters
object
| the object to search for |
Returns
- true if object is an element of this List, false otherwise
public
boolean
containsAll(Collection<?> collection)
Searches this List for all objects in the specified Collection.
Parameters
collection
| the Collection of objects |
Returns
- true if all objects in the specified Collection are elements of
this List, false otherwise
public
boolean
equals(Object object)
Compares the argument to the receiver, and returns true if they represent
the
same object using a class specific comparison.
Parameters
object
| Object the object to compare with this object. |
Returns
- boolean
true
if the object is the same as this
object false
if it is different from this object.
public
E
get(int location)
Returns the element at the specified location in this List.
Parameters
location
| the index of the element to return |
Returns
- the element at the specified location
public
int
hashCode()
Returns an integer hash code for the receiver. Objects which are equal
answer the same value for this method.
public
int
indexOf(Object object)
Searches this List for the specified object and returns the index of the
first occurrence.
Parameters
object
| the object to search for |
Returns
- the index of the first occurrence of the object
public
boolean
isEmpty()
Returns if this List has no elements, a size of zero.
Returns
- true if this List has no elements, false otherwise
public
Iterator<E>
iterator()
Returns an Iterator on the elements of this List. The elements are
iterated in the same order that they occur in the List.
Returns
- an Iterator on the elements of this List
public
int
lastIndexOf(Object object)
Searches this List for the specified object and returns the index of the
last occurrence.
Parameters
object
| the object to search for |
Returns
- the index of the last occurrence of the object
public
ListIterator<E>
listIterator()
Returns a ListIterator on the elements of this List. The elements are
iterated in the same order that they occur in the List.
Returns
- a ListIterator on the elements of this List
public
ListIterator<E>
listIterator(int location)
Returns a ListIterator on the elements of this List. The elements are
iterated in the same order that they occur in the List. The iteration
starts at the specified location.
Parameters
location
| the index at which to start the iteration |
Returns
- a ListIterator on the elements of this List
public
E
remove(int location)
Removes the object at the specified location from this List.
Parameters
location
| the index of the object to remove |
public
boolean
remove(Object object)
Removes the first occurrence of the specified object from this List.
Parameters
object
| the object to remove |
Returns
- true if this List is modified, false otherwise
public
boolean
removeAll(Collection<?> collection)
Removes all occurrences in this List of each object in the specified
Collection.
Parameters
collection
| the Collection of objects to remove |
Returns
- true if this List is modified, false otherwise
public
boolean
retainAll(Collection<?> collection)
Removes all objects from this List that are not contained in the
specified Collection.
Parameters
collection
| the Collection of objects to retain |
Returns
- true if this List is modified, false otherwise
public
E
set(int location, E object)
Replaces the element at the specified location in this List with the
specified object.
Parameters
location
| the index at which to put the specified object |
object
| the object to add |
Returns
- the previous element at the index
public
int
size()
Returns the number of elements in this List.
Returns
- the number of elements in this List
public
List<E>
subList(int start, int end)
Returns a List of the specified portion of this List from the start index
to one less than the end index. The returned List is backed by this list
so changes to one are reflected by the other.
Parameters
start
| the index at which to start the sublist |
end
| the index one past the end of the sublist |
Returns
- a List of a portion of this List
public
T[]
toArray(T[] array)
Returns an array containing all elements contained in this List. If the
specified array is large enough to hold the elements, the specified array
is used, otherwise an array of the same type is created. If the specified
array is used and is larger than this List, the array element following
the collection elements is set to null.
Returns
- an array of the elements from this List
Throws
ArrayStoreException
| when the type of an element in this List cannot be stored
in the type of the specified array
|
public
Object[]
toArray()
Returns an array containing all elements contained in this List.
Returns
- an array of the elements from this List