Skip to content

18 Arrays ​

An array is indexed like a list but keeps a fixed length.

norm
main() {
  Array<Integer> scores = [3, 5, 8]
  scores[1] = 7
  printLine(scores[0])
  printLine(scores[1])
  printLine(scores.size())
  Integer total = scores[0] + scores[1] + scores[2]
  printLine(total)
  printLine(scores[2])
}

Expected output:

text
3
7
3
18
8

Array<Integer> gives the literal an array type. Replacing scores[1] changes that element, while size() stays three; use a list when the number of elements must grow.

Try it: Replace the first element and print it again.

Precise rules: Reference.

Norm 0.25