Represents a collection in which every element has a unique non-negative integer index.
A List
is a Collection
of its elements, and a
Correspondence
from indices to elements.
Direct access to a list element by index produces a
value of optional type. The following idiom may be
used instead of upfront bounds-checking, as long as
the list element type is a non-null
type:
value char = "hello world"[index]; if (exists char) { /*do something*/ } else { /*out of bounds*/ }
To iterate the indexes of a List
, use the following
idiom:
for (i->char in "hello world".indexed) { ... }
Attributes | |
first | Source Code Returns the first element of this Refined declaration: first |
hash | Source Code shared actual default Integer hash The hash value of the value, which allows the value
to be an element of a hash-based set or key of a
hash-based map. Implementations must respect the
constraint that if Refined declaration: hash |
last | Source Code Returns the last element of this Refined declaration: last |
lastIndex | Source Code shared formal Integer? lastIndex The index of the last element of the list, or null if the list is empty. See also: List.size |
rest | Source Code The rest of the list, without the first element. Refined declaration: rest |
reversed | Source Code Reverse this list, returning a new list. |
size | Source Code shared actual default Integer size The number of elements in this sequence, always
See also: List.lastIndex Refined declaration: size |
Inherited Attributes |
Attributes inherited from: Object |
Attributes inherited from: Cloneable<Clone> |
Attributes inherited from: Collection<Element> |
Attributes inherited from: Correspondence<Key,Item> |
Attributes inherited from: Iterable<Element,Absent> |
Methods | |
contains | Source Code |
defines | Source Code Determines if the given index refers to an element of this sequence, that is, if `index<=sequence.lastIndex`. Refined declaration: defines |
endsWith | Source Code Determine if the given list occurs at the end of this list. |
equals | Source Code Two
Refined declaration: equals |
findLast | Source Code The last element which satisfies the given
predicate, if any, or Refined declaration: findLast |
firstInclusion | Source Code The first index in this list at which the given list occurs. |
firstOccurrence | Source Code The first index in this list at which the given element occurs. |
get | Source Code Returns the element of this sequence with the given index, or `null` if the given index is past the end of the sequence, that is, if `index>sequence.lastIndex`. The first element of the sequence has index `0`. Refined declaration: get |
includes | Source Code Determine if the given list occurs at some index in this list. |
includesAt | Source Code Determine if the given list occurs at the given index of this list. Parameters:
|
inclusions | Source Code The indexes in this list at which the given list occurs. |
indexes | Source Code The indexes in this list for which the element satisfies the given predicate. Parameters:
|
initial | Source Code Select the first elements of this list, returning a list no longer than the given length. If this list is shorter than the given length, return this list. Otherwise return a list of the given length. See also: List.terminal |
iterator | Source Code An iterator for the elements belonging to this container. Refined declaration: iterator |
lastInclusion | Source Code The last index in this list at which the given list occurs. |
lastOccurrence | Source Code The last index in this list at which the given element occurs. |
longerThan | Source Code Determines if this iterable object has more elements than the given length. This is an efficient operation for iterable objects with many elements. Refined declaration: longerThan |
occurrences | Source Code The indexes in this list at which the given element occurs. |
occurs | Source Code Determines if the given value occurs as an element in this list. |
occursAt | Source Code Determines if the given value occurs at the given index in this list. |
shorterThan | Source Code Determines if this iterable object has fewer elements than the given length. This is an efficient operation for iterable objects with many elements. Refined declaration: shorterThan |
startsWith | Source Code Determine if the given list occurs at the start of this list. |
terminal | Source Code Select the last elements of the list, returning a list no longer than the given length. If this list is shorter than the given length, return this list. Otherwise return a list of the given length. See also: List.initial |
trim | Source Code Trim the elements satisfying the given predicate function from the start and end of this list, returning a list no longer than this list. |
trimLeading | Source Code Trim the elements satisfying the given predicate function from the start of this list, returning a list no longer than this list. |
trimTrailing | Source Code Trim the elements satisfying the given predicate function from the end of this list, returning a list no longer than this list. |
withLeading | Source Code Returns a new Parameters:
See also: following |
withTrailing | Source Code Returns a new Parameters:
|
Inherited Methods |
Methods inherited from: Category |
Methods inherited from: Correspondence<Key,Item> |
Methods inherited from: Iterable<Element,Absent> any, by, chain, collect, count, cycle, defaultNullElements, every, filter, find, findLast, fold, following, iterator, longerThan, map, repeat, select, shorterThan, skipping, skippingWhile, sort, taking, takingWhile |
Methods inherited from: Ranged<Index,Span> |