Slawomir Ziolkowski
04/18/2020, 11:18 AMfun main(args: Array<String>) {
val firstList = listOf<User>(
User(name="P-0"), User(name="P-0"), User(name="P-0"),
User(name="P-2"), User(name="P-2"), User(name="P-2"), User(name="P-2")
)
val secondList = listOf<User>(User(name="P-2"))
print(firstList.minus(secondList))
}
data class User(val name: String)
I expect that only one P-2 element will be not in the result, but the result looks like this:
[User(name=P-0), User(name=P-0), User(name=P-0)]Dan Newton
04/18/2020, 11:34 AMclass
instead of a data class
it should do what you wantdata class
overrides the hashCode
depending on the class’s propertiesMike
04/18/2020, 11:52 AMminus
or -
function implementation in the stdlib, and you'll see it's effectively a filter
.
So basically, filter all elements from the first list that are in the second.Kroppeb
04/18/2020, 11:57 AMif you used a class instead of a data class it should do what you wantNo, not using a
data class
would remove no itemsSlawomir Ziolkowski
04/18/2020, 2:21 PMmolikuner
04/18/2020, 10:21 PMDan Newton
04/18/2020, 10:45 PMSlawomir Ziolkowski
04/20/2020, 12:11 PM