Map

A list contains a collection of single objects. Maps, on the other hand, are data structures that hold collections of key value pairs. In Kotlin, there are three different types of pairs:

  • Pairs of strings: <String,String>
  • Pairs of ints: <Int,Int>
  • Pairs of an init and a string: <Int,String>

The following is an example of a pair:

var p1 = Pair(1,"One")
var p2 = 2 to "Two"

Just like other Kotlin collections, there are two types of maps:

  • Immutable maps
  • Mutable maps

In this section, we will start by looking at immutable maps.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.10.1