mergeIfNotContained
Method used to merge items from the collectionToMerge collection that are not present in the main collection. For example:
val mainCollection = mutableListOf(1, 2, 3)
val collectionToMerge = listOf(2, 3, 4)
// apply the retainAndAdd method
mainCollection.mergeIfNotContained(
collectionToMerge = collectionToMerge
)
println(mainCollection) // the result printed will be 1, 2, 3, 4
Content copied to clipboard
The duplicate values will be considered as one element, so will be merged