Scala MapsMap 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 ExampleIn 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 ElementsYou 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
|