87
Scala Maps
Map is used to store elements. It stores elements in pairs of key and values. In scala, you can create map by using two ways either by using comma separated pairs or by using rocket operator.
Scala maps Example
In the following example, we have both approaches to create map.
Output:
Map(A -> Apple, B -> Ball) Map(A -> Aple, B -> Ball) Empty Map: Map()
Scala Map Example: Adding and Removing Elements
You can add and remove new elements in maps. Scala provides you lots of predefined method. You can use them to perform operations on the Maps. In the following example, we have created a new Map.
Output:
Apple Map(A -> Apple, B -> Ball, C -> Cat) Map(A -> Apple, C -> Cat)
Next TopicScala HashMap