Created
February 24, 2021 08:43
-
-
Save kibotu/09a12b8c02b1f5f747c1b6927795b660 to your computer and use it in GitHub Desktop.
working with quantities in kotlin.
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
val a = listOf("a", "b", "c", "d") | |
val b = listOf("d", "e", "f", "a") | |
println("a=$a b=$b") // a=[a, b, c, d] b=[d, e, f, a] | |
println("combined ${a + b}") // combined [a, b, c, d, d, e, f, a] | |
println("union ${a.union(b)}") // union [a, b, c, d, e, f] | |
val ab = a.toMutableList() | |
ab.retainAll(b) | |
println("a retainAll b $ab") // a retainAll b [a, d] | |
val ba = b.toMutableList() | |
ba.retainAll(a) | |
println("b retainAll a $ba") // b retainAll a [d, a] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
also good examples can be found here
https://kotlinlang.org/docs/collections-overview.html
https://zetcode.com/kotlin/lists/