How to declare

Let's start by declaring Pair and Triple. Like other variables, Pair and Triple can be declared by using the val or var keyword:

val mobile = Pair("Google", 500)
val screenMirror = Pair("Chrome cast", 20.5)
val addressBook = Triple("Khan", 123456789, "Stockholm")

First, create a variable by directly assigning some values with Pair or Triple. As we can see, each Pair and Triple contains different data types—a mobile Pair contains a string and integer set, screenMirror contains a string and a double, and an addressBook Triple contains two strings and one integer. We can see that an explicit declaration of a data type is not required, as the Kotlin type inference automatically finds out the variable type.

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

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