Start learning free

LESSON 108 OF 677 · ARRAYS I

List Size in Scala

Lesson

We can get the number of elements in a Scala collection such as a List or an ArrayBuffer using .size.

val ages = List(14, 32, 50, 21)
println(ages.size)

// prints 4

Assignment
Follow the Coding Tutorial and print the list size.


Hint
Use ages.size.


STEP 1 OF 3
    Ctrl + Enter to check