Stenway Developer Network

Arrays

Empty array

array1 Array<int>
array2 Array<int> = []
array3 Array<int> = new Array<int>()

Array

array1 Array<int> = [1, 2, 3]
array2 Array<bool> = [true, false, true]
array3 Array<string> = ["Hello", "World", "!"]
array4 Array<object> = ["Hello", 2, true]

Size

array1 Array<int>(3)
array2 Array<int> = new Array<int>(3)

Is equal to:

array1 Array<int> = [0, 0, 0]

Nullable

Size

array1 Array<int?>(3)
array2 Array<int?> = new Array<int?>(3)

Is equal to:

array1 Array<int?> = [null, null, null]

Jagged Arrays

arrayOfArrays Array<Array<String>> = [["A1", "A2"], ["B1"], ["C1", "C2", "C3"]]

Access

array Array<int> = [1, 2, 3]
firstElement int = array[0]
array[1] = 123

Iterating

array Array<int> = [1, 2, 3]
foreach x int in array
  this.doSomething(x)
end
array Array<int> = [1, 2, 3]
for i int = 0 to array.size-1 by 1
  value int = array[i]
  this.doSomething(value)
end