Reference:Java.util.List

From Triled Wiki

Jump to: navigation, search


java.util
public interface java.util.List

java.util.List Collection
List is a collection which maintains an ordering for its elements. Every element in the list has an index.

Contents

[edit] Known Indirect Subclasses

AbstractList, AbstractSequentialList, ArrayList, CopyOnWriteArrayList, LinkedList, Stack, Vector

[edit] Summary

[edit] Public Methods

        void  add (int location, E object)
Inserts the specified object into this Vector at the specified location.
        boolean  add (E object)
Adds the specified object at the end of this List.
        boolean  )">addAll (int location, Collection collection)
Inserts the objects in the specified Collection at the specified location in this List.
        boolean  )">addAll (Collection collection)
Adds the objects in the specified Collection to the end of this List.
        void  clear ()
Removes all elements from this List, leaving it empty.
        boolean  contains (Object object)
Searches this List for the specified object.
        boolean  )">containsAll (Collection collection)
Searches this List for all objects in the specified Collection.
        boolean  equals (Object object)
Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.
        E   get (int location)
Answers the element at the specified location in this List.
        int  hashCode ()
Answers an integer hash code for the receiver.
        int  indexOf (Object object)
Searches this List for the specified object and returns the index of the first occurrence.
        boolean  isEmpty ()
Answers if this List has no elements, a size of zero.
        Iterator   iterator ()
Answers an Iterator on the elements of this List.
        int  lastIndexOf (Object object)
Searches this List for the specified object and returns the index of the last occurrence.
        ListIterator   listIterator ()
Answers a ListIterator on the elements of this List.
        ListIterator   listIterator (int location)
Answers a ListIterator on the elements of this List.
        E   remove (int location)
Removes the object at the specified location from this List.
        boolean  remove (Object object)
Removes the first occurrence of the specified object from this List.
        boolean  )">removeAll (Collection collection)
Removes all occurrences in this List of each object in the specified Collection.
        boolean  )">retainAll (Collection collection)
Removes all objects from this List that are not contained in the specified Collection.
        E   set (int location, E object)
Replaces the element at the specified location in this List with the specified object.
        int  size ()
Answers the number of elements in this List.
        List   subList (int start, int end)
Answers a List of the specified portion of this List from the start index to one less than the end index.
        T[toArray (T[ ] array)
Answers an array containing all elements contained in this List.
        Object[toArray ()
Answers an array containing all elements contained in this List.

[edit] Methods inherited from interface java.util.Collection
add, )">addAll, clear, contains, )">containsAll, equals, hashCode, isEmpty, iterator, remove, )">removeAll, )">retainAll, size, toArray, toArray
[edit] Methods inherited from interface java.lang.Iterable

iterator

[edit] Details

[edit] Public Methods

[edit] 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

Throws

UnsupportedOperationException when adding to this List is not supported
ClassCastException when the class of the object is inappropriate for this List
IllegalArgumentException when the object cannot be added to this List
IndexOutOfBoundsException when location < 0 >= size()

[edit] public boolean add(E object)

Adds the specified object at the end of this List.

Parameters

object the object to add

Returns

  • true

Throws

UnsupportedOperationException when adding to this List is not supported
ClassCastException when the class of the object is inappropriate for this List
IllegalArgumentException when the object cannot be added to this List

[edit] public boolean addAll(int location, Collection 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

Throws

UnsupportedOperationException when adding to this List is not supported
ClassCastException when the class of an object is inappropriate for this List
IllegalArgumentException when an object cannot be added to this List
IndexOutOfBoundsException when location < 0 >= size()

[edit] public boolean addAll(Collection 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

Throws

UnsupportedOperationException when adding to this List is not supported
ClassCastException when the class of an object is inappropriate for this List
IllegalArgumentException when an object cannot be added to this List

[edit] public void clear()

Removes all elements from this List, leaving it empty.

Throws

UnsupportedOperationException when removing from this List is not supported

See Also

[edit] 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

[edit] 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

[edit] public boolean equals(Object object)

Compares the argument to the receiver, and answers 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.

See Also

[edit] public E get(int location)

Answers 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

Throws

IndexOutOfBoundsException when location < 0 >= size()

[edit] public int hashCode()

Answers an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Returns

  • the receiver's hash

See Also

[edit] 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

[edit] public boolean isEmpty()

Answers if this List has no elements, a size of zero.

Returns

  • true if this List has no elements, false otherwise

See Also

[edit] public Iterator iterator()

Answers 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

See Also

[edit] 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

[edit] public ListIterator listIterator()

Answers 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

See Also

[edit] public ListIterator listIterator(int location)

Answers 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

Throws

IndexOutOfBoundsException when location < 0 >= size()

See Also

[edit] public E remove(int location)

Removes the object at the specified location from this List.

Parameters

location the index of the object to remove

Returns

  • the removed object

Throws

UnsupportedOperationException when removing from this List is not supported
IndexOutOfBoundsException when location < 0 >= size()

[edit] 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

Throws

UnsupportedOperationException when removing from this List is not supported

[edit] 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

Throws

UnsupportedOperationException when removing from this List is not supported

[edit] 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

Throws

UnsupportedOperationException when removing from this List is not supported

[edit] 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

Throws

UnsupportedOperationException when replacing elements in this List is not supported
ClassCastException when the class of an object is inappropriate for this List
IllegalArgumentException when an object cannot be added to this List
IndexOutOfBoundsException when location < 0 >= size()

[edit] public int size()

Answers the number of elements in this List.

Returns

  • the number of elements in this List

[edit] public List subList(int start, int end)

Answers 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

Throws

IndexOutOfBoundsException when start < 0, start > end or end > size()

[edit] public T[ ]toArray(T[ ] array)

Answers 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.

Parameters

array the array

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

[edit] public Object[ ]toArray()

Answers an array containing all elements contained in this List.

Returns

  • an array of the elements from this List

[edit] References

Personal tools