klyn.collections.ArrayList.operator[]
method
public native operator[](index as Long) as T
Description

Gets the element at the given index. Indexed assignment replaces an existing element; assigning at index size appends one element without allowing holes in the list. Slices copy only the selected elements. Slice assignment captures the source before writing, so the source may alias this list. Compatible primitive replacements retain packed storage, including when the list changes size. All replacement elements are validated before any target element changes. For contiguous lists, a same-size replacement takes O(k) time for k source elements; resizing also moves the suffix and may grow the backing buffer.

data = ArrayList<Int>()
data[0] = 10    # equivalent to data.add(10)
data[0] = 20    # replaces the first element
print(data[0])  # 20
data[:] = [10, 20, 30]
data[1:2] = [40, 50]
print(data)     # [10, 40, 50, 30]
Parameters
ParameterDescription
indexZero-based index.
Throws
  • IndexException if index is invalid.