Arrays
Arrays in THP use exclusively square brackets.
More importantly, Arrays and Maps are different. Arrays only store values of a single datatype.
Usage
val fruits = ["apple", "banana", "cherry"]
val apple = fruits[0]
print(apple) // apple
// To mutate an array, you need to declare it as var
var numbers = [0, 1, 2, 3]
numbers[3] = 5
print(numbers[3]) // 5
thp
Type signature
Array[String]
Array[Int]
thp
The Array signature requires the word Array
.
There is no Int[]
or [Int]
signature, since that would cause
problems with the languageās grammar.