Skip to content

13 Lists ​

A list stores an ordered sequence whose length can change.

norm
main() {
  List<String> tasks = ["read", "run"]
  tasks.add("change")
  tasks.add("share")
  printLine(tasks[0])
  printLine(tasks.size())
  printLine(tasks[2])
  printLine(tasks[1])
  printLine(tasks[3])
}

Expected output:

text
read
4
change
run
share

List<String> fixes the element type, while the literal supplies the initial elements. add appends an element; indexing starts at zero, and size() reports the current length.

Try it: Add one more task and update the final index.

Precise rules: Reference.

Norm 0.25