retainAndAdd
Method split in two phases used to first remove all the items from the main collection that are not present in the supportCollection, then add all the items present in the same support collection but not in the main one. For example:
val mainCollection = mutableListOf(1, 2, 3)
val supportCollection = listOf(2, 3, 4)
// apply the retainAndAdd method
mainCollection.retainAndAdd(
supportCollection = supportCollection
)
println(mainCollection) // the result printed will be 2, 3, 4
Content copied to clipboard
The duplicate values will be considered as one element, so will be merged