Hello all, not sure if this is a noob question but...
# getting-started
a
Hello all, not sure if this is a noob question but here it goes: How can I get the difference between two List/ArrayList regardless of the order of the sentence? I mean, for example these two lists
Copy code
val first = listOf(1, 2, 3, 4, 5)
 val second = listOf(1, 2, 3)
If I use
first.minus(second)
I’ll get
[4, 5]
but If I use
second.minus(first)
I’ll get
[]
p
You can convert to sets and get the symmetric difference, though there's no convenient standard library function, interestingly
a
Thanks @Paul Griffith
j
They have added recently the
intersect
function to the stdlib, I think they should add the opposite too
i
@Javier, No
intersect
was not added recently, it's been there quite a long time
@Alejandro Rios There's a request about adding symmetric difference to stdlib, https://youtrack.jetbrains.com/issue/KT-11330, but we're not sure about its use cases. Can you describe yours?
j
Maybe union was? Don't remember then. I am going to like that issue, I had the difference as extension function since 2019.
a
That's really cool, thanks for the update
i
@Javier How do you use your extension function in your code? What tasks do you solve with it?
j
For example in an android app, we had multiple lists of quizzes, generally a pair of lists, and was a requirement to get the difference of quizzes to show them to the user.