List<E> Interface
A List is an indexable collection with a length. It can be of fixed size or extendable.
Default class
Extends
Implemented by
Constructors
Code new List.from(Iterable other) #
Creates a list with the elements of other. The order in the list will be the order provided by the iterator of other.
List.from(Iterable<E> other);
Methods
Code operator [](int index) #
Returns the element at the given index in the list or throws an IndexOutOfRangeException if index is out of bounds.
E operator [](int index);
Code void operator []=(int index, value) #
Sets the entry at the given index in the list to value. Throws an IndexOutOfRangeException if index is out of bounds.
void operator []=(int index, E value);
Code void add(value) #
Adds value at the end of the list, extending the length by one. Throws an UnsupportedOperationException if the list is not extendable.
void add(E value);
Code void addAll(Collection collection) #
Appends all elements of the collection to the end of list. Extends the length of the list by the length of collection. Throws an UnsupportedOperationException if the list is not extendable.
void addAll(Collection<E> collection);
Code void addLast(value) #
Adds value at the end of the list, extending the length by one. Throws an UnsupportedOperationException if the list is not extendable.
void addLast(E value);
Code void clear() #
Removes all elements in the list. The length of the list becomes zero. Throws an UnsupportedOperationException if the list is not extendable.
void clear();
Code List getRange(int start, int length) #
Returns a sub list copy of this list, from
start to
start + length.
Returns an empty list if
length is 0.
Throws an IllegalArgumentException if
length is negative.
Throws an IndexOutOfRangeException if
start or
start + length are out of range.
List<E> getRange(int start, int length);
Code int indexOf(element, [int start]) #
Returns the first index of element in this list. Searches this list from index start to the length of the list. Returns -1 if element is not found.
int indexOf(E element, [int start]);
Code void insertRange(int start, int length, [initialValue]) #
Inserts a new range in the list, starting from
start to
start + length. The entries are filled with
initialValue.
Throws an UnsupportedOperationException if the list is
not extendable.
If
length is 0, this method does not do anything.
If
start is the length of the array, this method inserts the
range at the end of the array.
Throws an IllegalArgumentException if
length is negative.
Throws an IndexOutOfRangeException if
start or
start + length are out of range.
void insertRange(int start, int length, [E initialValue]);
Code last() #
Returns the last element of the list, or throws an out of bounds exception if the list is empty.
E last();
Code int lastIndexOf(element, [int start]) #
Returns the last index of element in this list. Searches this list from index start to 0. Returns -1 if element is not found.
int lastIndexOf(E element, [int start]);
Code void set length(int newLength) #
Changes the length of the list. If
newLength is greater than
the current length, entries are initialized to null. Throws
an UnsupportedOperationException if the list is not extendable.
void set length(int newLength);
Code removeLast() #
Pops and returns the last element of the list. Throws a UnsupportedOperationException if the length of the list cannot be changed.
E removeLast();
Code void removeRange(int start, int length) #
Removes the range in the list starting from
start to
start + length.
Throws an UnsupportedOperationException if the list is
not extendable.
If
length is 0, this method does not do anything.
Throws an IllegalArgumentException if
length is negative.
Throws an IndexOutOfRangeException if
start or
start + length are out of range.
void removeRange(int start, int length);
Code void setRange(int start, int length, List from, [int startFrom]) #
Copies
length elements of the
from array, starting
from
startFrom, into this, starting at
start.
If
length is 0, this method does not do anything.
Throws an IllegalArgumentException if
length is negative.
Throws an IndexOutOfRangeException if
start or
start + length are out of range for this, or if
startFrom is out of range for
from.
void setRange(int start, int length, List<E> from, [int startFrom]);
Code void sort(int compare(a, b)) #
Sorts the list according to the order specified by the comparator. The order specified by the comparator must be reflexive, anti-symmetric, and transitive.
The comparator function
compare must take two arguments a and b
and return
an integer strictly less than 0 if a < b, 0 if a = b, and an integer strictly greater than 0 if a > b.
void sort(int compare(E a, E b));