Last active
March 14, 2020 12:19
-
-
Save magdamiu/a3cbbd009961e310a27f3f42055a3201 to your computer and use it in GitHub Desktop.
Pair samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// combine different data types | |
val testName = "Kotlin Test" | |
val grade = 10 | |
val resultTest = Pair (testName, grade) | |
println(resultTest) | |
// get the parts of Pair | |
val book = Pair("Learn Kotlin from GDE", 20) | |
val (title , price) = book | |
println("Title = ${book.first} , Price = ${book.second}") | |
// infix function | |
val yellowScarf = "yellow" to "scarf" | |
println(yellowScarf.first) // => yellow | |
println(yellowScarf.second) // => scarf | |
// nesting with parentheses | |
val clothes = ("yellow" to "scarf") to ("blue" to "blouse") | |
println(clothes.second.first) // => blue | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment