Start learning free

LESSON 104 OF 677 · ARRAYS I

Accessing List Elements in Scala

Lesson

Scala lists, and buffers such as ArrayBuffer, use zero-based indexing. Access an element by writing the index in parentheses.

val ages = List(14, 32, 50, 21)
println(ages(0)) // 14
println(ages(2)) // 50

Assignment
Follow the Coding Tutorial and access elements from the list.


Hint
The first element is at index 0.


STEP 1 OF 3
    Ctrl + Enter to check