Start learning free

LESSON 91 OF 348 · ARRAYS I

Accessing List Elements in Scala in Scala

Lesson

Scala lists 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

    Accessing Elements in Scala

    Keep going with ScalaAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free