Start learning free

LESSON 103 OF 348 · DICTIONARIES

Updating Map Values in Scala in Scala

Lesson

Immutable maps return a new map when updated. Mutable maps can be changed in place.

var ages = Map("Ana" -> 12)
ages = ages.updated("Ana", 13)
println(ages("Ana"))

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

    Updating 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