Start learning free

LESSON 104 OF 348 · DICTIONARIES

Map Size in Scala in Scala

Lesson

Use .size to get the number of key-value pairs in a Scala Map.

val ages = Map("Ana" -> 12, "Ben" -> 15)
println(ages.size)

Assignment
Follow the Coding Tutorial and practice using maps.


Hint
Use key -> value pairs when creating a map.


STEP 1 OF 1
    Ctrl + Enter to check

    Dictionary Length 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