October 2018
Intermediate to advanced
370 pages
9h 15m
English
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.
Read now
Unlock full access