Start learning free

LESSON 102 OF 348 · DICTIONARIES

Accessing Map Values in Scala in Scala

Lesson

Access a value in a Scala Map by writing the key in parentheses.

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

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

    Accessing Dictionary Values 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