Skip to content

Instantly share code, notes, and snippets.

@kibotu
Created February 24, 2021 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kibotu/09a12b8c02b1f5f747c1b6927795b660 to your computer and use it in GitHub Desktop.
Save kibotu/09a12b8c02b1f5f747c1b6927795b660 to your computer and use it in GitHub Desktop.
working with quantities in kotlin.
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]
@kibotu
Copy link
Author

kibotu commented Feb 24, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment