Skip to content

Instantly share code, notes, and snippets.

@magdamiu

magdamiu/Collections.kt

Last active Mar 14, 2020
Embed
What would you like to do?
Pair samples
// 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