Scala Mapping


Release date:2023-11-18 Update date:2023-11-21 Editor:admin View counts:177

Label:

Scala Mapping

mapping is an iterative key-value pair (key/value) structure.

All values can be obtained by key.

The keys in Map are unique.

Map also known as Hash tables.

Map has two types, mutable and immutable, the difference is that a mutable object can modify it, while an immutable object cannot.

Scala usage is immutable by default Map . If you need to use mutable sets, you need to explicitly introduce import scala.collection.mutable.Map Class

In Scala, you can use both mutable and immutable. Map immutable direct use Map , variable use mutable.Map . The following example demonstrates immutability Map application:

// An empty hash table with keys as strings and values as integers
var A:Map[Char,Int] = Map()

// Map Key Value Pair Demonstration
val colors = Map("red" -> "#FF0000", "azure" -> "#F0FFFF")

Define Map you need to define a type for the key-value pair. If you need to add key-value , you can use the + sign, as follows:

Powered by TorCMS (https://github.com/bukun/TorCMS).