Array
classin packageklyn.collections
public class Array<T> extends Object implements IList<T>:
└ Array
All Implemented Interfaces: IList

Fixed-size contiguous array.

This collection stores a fixed number of elements. Unlike ArrayList<T>, its length is decided at construction time and cannot change afterwards.

The language also exposes the shorthand syntax T[] for this type and T[n] for array allocation.

import klyn.collections

data as UInt[] = UInt[3]
data[0] = 10u
data[1] = 20u
data[2] = 30u
print(data)          # f:[10, 20, 30]
print(data.size)     # 3
Since

1.0

Properties
Modifier and Type Member Description
public readonly native property size
size as ULong
Returns the number of elements in the array.
Inherited Properties
propertyInherited Properties from Object: type
propertyInherited Properties from IList: size
Constructors
Modifier and Type Member Description
public Array
Array(source as IList<T>):
Creates a fixed-size array by copying an existing ordered collection.
public native Array
Array(size as Int)
Creates a new array with a fixed number of elements.
Methods
Modifier and Type Member Description
public native count
count(item as T) as ULong
Counts occurrences of the given element.
public native indexOf
indexOf(item as T, start as Int = 0) as Int
Returns the first index of the given element.
public native join
join(separator as String) as String
Joins array elements into a single string.
public native lastIndexOf
lastIndexOf(item as T, start as Int = -1) as Int
Returns the last index of the given element.
public native reverse
reverse() as Void
Reverses array elements in-place.
public native reverseNew
reverseNew() as Array<T>
Returns a reversed copy without modifying the current array.
public native sort
sort() as Void
Sorts array elements in-place.
public native sortNew
sortNew() as Array<T>
Returns a sorted copy without modifying the current array.
public native override toString
toString() as String
Returns the fixed-array textual representation.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, toDict, toJson, toString, toXml
methodInherited Methods from IList: count, indexOf, join, lastIndexOf
Operators
Modifier and Type Member Description
public native operator in(item as T) as Boolean Returns true when the array contains the given element.
public native static operator!=(readonly notnull left as Array, readonly notnull right as Array) as Boolean Compares two arrays structurally for inequality.
public native static operator+(readonly notnull left as Array<T>, readonly notnull right as Array<T>) as Array<T> Concatenates two fixed arrays into a new fixed array.
public native static operator==(readonly notnull left as Array, readonly notnull right as Array) as Boolean Compares two arrays structurally.
public native operator[](index as Int) as T Returns or replaces the element at the given index.
Inherited Operators
operatorInherited Operators from IList: operator in(item as T) as Boolean, operator[](index as Int) as T