Array

class Array<T>(source)

A fixed-size, mutable array of T elements.

Indices start at zero and end at size - 1. Changing an element does not change the array length. Equality compares array identity, not element contents.

The initializer constructor calls its callback once for each index, in ascending order. Copies share element references; they do not clone referenced objects.

Type Parameters

T

the element type.

Constructors

Link copied to clipboard
constructor(size: Int, init: (Int) -> T)

Creates an array by invoking init once for each index in ascending order.

Properties

Link copied to clipboard
external val size: Int

The number of elements in this array; always non-negative and unchanged after creation.

Functions

Link copied to clipboard
external fun <T> Array<out T>.copyInto(destination: Array<T>, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): Array<T>

Copies this range into destination, supporting overlapping ranges, and returns it.

Link copied to clipboard
external fun <T> Array<T>.copyOf(): Array<T>

Returns a new array containing the same elements.

external fun <T> Array<T>.copyOf(newSize: Int): Array<T?>

Returns a resized copy, padding extra elements with null.

Link copied to clipboard
external fun <T> Array<T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T>

Returns a new array containing elements from fromIndex up to, but excluding, toIndex.

Link copied to clipboard
operator external fun get(index: Int): T

Returns the element at index.

Link copied to clipboard
operator external fun iterator(): Iterator<T>

Structural declaration for direct array loops; stored iterators are not executable.

Link copied to clipboard
operator external fun set(index: Int, value: T)

Replaces the element at index with value.