October 2018
Intermediate to advanced
370 pages
9h 15m
English
Create an immutable map using the mapOf function and insert different pairs that contain init as a key and a string as a value:
val map: Map<Int,String> = mapOf( Pair(1,"One"), Pair(2,"Two"), ,Pair(3,"Three"), 4 to "Four", 5 to "Five")
Take a look at the following diagram of the Map interface:

We can access each pair using a for loop. Pairs provide two properties: key and value. Take a look at the following example, which uses a for loop to print each pair:
for(pair in map) { println("${pair.key} ${pair.value}")}
Like sets, maps do not support duplicate values. We can check this by adding more than one pair of the same type ...
Read now
Unlock full access