A fixed-sized array of mutable elements. An empty array is an array of size 0. Any element of an array may be set to a new value.

value array = Array { "hello", "world" };
array.set(0, "goodbye");

This class is provided primarily to support interoperation with Java, and for some performance-critical low-level programming tasks.

no subtypes hierarchy

Initializer
Array({Element*} elements)
Attributes
emptySource Codeshared actual Boolean empty

Determines if the stream is empty, that is to say, if the iterator returns no elements.

Refines Collection.empty ultimately refines Iterable.empty
firstSource Codeshared actual Element? first

The first element returned by the iterator, if any, or null if this stream is empty. For a stream with an unstable iteration order, a different value might be produced each time first is evaluated.

Refines List.first ultimately refines Iterable.first
lastSource Codeshared actual Element? last

The last element returned by the iterator, if any, or null if this stream is empty. In the case of an infinite stream, this operation never terminates; furthermore, this default implementation iterates all elements, which might be very expensive.

Refines List.last ultimately refines Iterable.last
lastIndexSource Codeshared actual Integer? lastIndex

The index of the last element of the list, or null if the list is empty.

sizeSource Codeshared actual Integer size

The number of elements returned by the Iterable.iterator() of this stream, if the iterator terminates. In the case of an infinite stream, this operation never terminates.

Refines List.size ultimately refines Iterable.size
Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Collection<Element>
Attributes inherited from: Correspondence<Key,Item>
Attributes inherited from: Iterable<Element,Absent>
Attributes inherited from: List<Element>
Methods
bySource Codeshared actual {Element*} by(Integer step)

Produces a stream containing every stepth element of this stream. If the step size is 1, the resulting stream contains the same elements as this stream.

For example, the expression

(0..10).by(3)

results in the stream { 0, 3, 6, 9 }.

The step size must be greater than zero.

Refines Iterable.by
cloneSource Codeshared actual Array<Element> clone()

A new array with the same elements as this array.

Refines List.clone ultimately refines Collection.clone
containsSource Codeshared actual Boolean contains(Object element)

Returns true if the given value belongs to this Category, that is, if it is an element of this Category, or false otherwise.

For most Categorys the following relationship is satisfied by every pair of elements x and y:

  • if x==y, then x in category == y in category

However, it is possible to form a useful Category consistent with some other equivalence relation, for example ===. Therefore implementations of contains() which do not satisfy this relationship are tolerated.

Refines List.contains ultimately refines Category.contains
copyToSource Codeshared void copyTo(Array<Element> destination, Integer sourcePosition = 0, Integer destinationPosition = 0, Integer length = ...)

Efficiently copy the elements in the segment sourcePosition:length of this array to the segment destinationPosition:length of the given array.

Parameters:
  • destination

    The array into which to copy the elements.

  • sourcePosition = 0

    The index of the first element in this array to copy.

  • destinationPosition = 0

    The index in the given array into which to copy the first element.

  • length = size-sourcePosition

    The number of elements to copy.

countSource Codeshared actual Integer count(Boolean selecting(Element element))

Produces the number of elements in this stream that satisfy the given predicate function. For an infinite stream, this method never terminates.

definesSource Codeshared actual Boolean defines(Integer index)

Determines if there is a value defined for the given key.

Refines List.defines ultimately refines Correspondence.defines
getFromFirstSource Codeshared actual Element? getFromFirst(Integer index)

Get the element at the specified index, or null if the index falls outside the bounds of this array.

Refines List.getFromFirst ultimately refines Iterable.getFromFirst
getFromLastSource Codeshared actual Element? getFromLast(Integer index)

Get the element at the specified index, where the array is indexed from the end of the array, or null if the index falls outside the bounds of this array.

iteratorSource Codeshared actual Iterator<Element> iterator()

An iterator for the elements belonging to this stream.

Refines List.iterator ultimately refines Iterable.iterator
measureSource Codeshared actual Array<Element> measure(Integer from, Integer length)

Obtain a measure containing the mapped values starting from the given starting index, with the given length. If length<=0, the resulting measure is empty.

The measure should contain the given number of elements of this stream, starting from the element at the given starting index, in the same order as they are produced by the Iterable.iterator() of the stream. In the case where the iterator would be exhausted before length elements are produced, the resulting measure contains only those elements which were produced before the iterator was exhausted, and the length of the measure is less then the given length.

When the given index does not belong to this ranged object, the behavior is implementation dependent.

Refines List.measure ultimately refines Ranged.measure
reverseInPlaceSource Codeshared void reverseInPlace()

Reverses the order of the current elements in this array. This operation modifies the array.

sequenceSource Codeshared actual Element[] sequence()

A sequence containing all the elements of this stream, in the same order they occur in this stream. This operation eagerly evaluates and collects every element of the stream.

setSource Codeshared void set(Integer index, Element element)

Replace the existing element at the specified index with the given element.

Parameters:
  • index

    The index of the element to replace.

  • element

    The new element.

Throws
  • AssertionError

    if the given index is out of bounds, that is, if index<0 or if index>lastIndex

skipSource Codeshared actual {Element*} skip(Integer skipping)

Produces a stream containing the elements of this stream, after skipping the first skipping elements produced by its iterator.

If this stream does not contain more elements than the specified number of elements to skip, the resulting stream has no elements. If the specified number of elements to skip is zero or fewer, the resulting stream contains the same elements as this stream.

sortSource Codeshared actual Element[] sort(Comparison comparing(Element x, Element y))

Produce a new sequence containing the elements of this stream, sorted according to the given comparator function imposing a partial order upon the elements of the stream.

For convenience, the functions byIncreasing() and byDecreasing() produce suitable comparator functions.

For example, this expression

"Hello World!".sort(byIncreasing(Character.lowercased))

evaluates to the sequence [ , !, d, e, H, l, l, l, o, o, r, W].

This operation is eager by nature.

Note that the toplevel function sort() may be used to sort a stream of Comparable values according to the natural order of its elements.

sortInPlaceSource Codeshared void sortInPlace(Comparison comparing(Element x, Element y))

Sorts the elements in this array according to the order induced by the given comparison function. This operation modifies the array.

Parameters:
  • comparing

    A comparison function that compares pairs of elements of the array.

spanSource Codeshared actual Array<Element> span(Integer from, Integer to)

Obtain a span containing the elements between the two given indices.

The span should contain elements of this stream, starting from the element at the given starting index, and ending with the element at the given ending index, in the same order as they are produced by the Iterable.iterator() of the stream, except when the ending index occurs earlier than the starting index, in which case they occur in the opposite order.

When one or both of the given indices does not belong to this ranged stream, the behavior is implementation dependent.

Refines List.span ultimately refines Ranged.span
spanFromSource Codeshared actual Array<Element> spanFrom(Integer from)

Obtain a span containing the elements between the given starting index and the last index of this ranged object.

The span should contain elements of this stream, starting from the element at the given starting index, in the same order as they are produced by the Iterable.iterator() of the stream.

When the given index does not belong to this ranged stream, the behavior is implementation dependent.

Refines List.spanFrom ultimately refines Ranged.spanFrom
spanToSource Codeshared actual Array<Element> spanTo(Integer to)

Obtain a span containing the elements between the first index of this ranged stream and given end index.

The span should contain elements of this stream, up to the element at the given ending index, in the same order as they are produced by the Iterable.iterator() of the stream.

When the given index does not belong to this ranged stream, the behavior is implementation dependent.

Refines List.spanTo ultimately refines Ranged.spanTo
takeSource Codeshared actual {Element*} take(Integer taking)

Produces a stream containing the first taking elements of this stream.

If the specified number of elements to take is larger than the number of elements of this stream, the resulting stream contains the same elements as this stream. If the specified number of elements to take is fewer than one, the resulting stream has no elements.

Inherited Methods
Methods inherited from: Object
Methods inherited from: Category<Element>
Methods inherited from: Collection<Element>
Methods inherited from: Correspondence<Key,Item>
Methods inherited from: Iterable<Element,Absent>
Methods inherited from: List<Element>
Methods inherited from: Ranged<Index,Element,Subrange>