retainAll
Retains only the elements in this collection that are contained in the specified collection.
Since Kotlin
1.0Return
true
if any element was removed from the collection, false
if the collection was not modified.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val collection: MutableCollection<Char> = mutableSetOf('a', 'b', 'c')
// Nothing was removed
println("collection.retainAll(listOf('a', 'b', 'c')) is ${collection.retainAll(listOf('a', 'b', 'c'))}") // false
println(collection) // [a, b, c]
println("collection.retainAll(listOf('a', 'e', 'i', 'o')) is ${collection.retainAll(listOf('a', 'e', 'i', 'o'))}") // true
println(collection) // [a]
//sampleEnd
}
Retains only the elements in this collection that are contained in the specified collection.
Since Kotlin
1.1Return
true
if any element was removed from the collection, false
if the collection was not modified.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val collection: MutableCollection<Char> = mutableSetOf('a', 'b', 'c')
// Nothing was removed
println("collection.retainAll(listOf('a', 'b', 'c')) is ${collection.retainAll(listOf('a', 'b', 'c'))}") // false
println(collection) // [a, b, c]
println("collection.retainAll(listOf('a', 'e', 'i', 'o')) is ${collection.retainAll(listOf('a', 'e', 'i', 'o'))}") // true
println(collection) // [a]
//sampleEnd
}
Retains only the elements in this collection that are contained in the specified collection.
Since Kotlin
1.0Return
true
if any element was removed from the collection, false
if the collection was not modified.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val collection: MutableCollection<Char> = mutableSetOf('a', 'b', 'c')
// Nothing was removed
println("collection.retainAll(listOf('a', 'b', 'c')) is ${collection.retainAll(listOf('a', 'b', 'c'))}") // false
println(collection) // [a, b, c]
println("collection.retainAll(listOf('a', 'e', 'i', 'o')) is ${collection.retainAll(listOf('a', 'e', 'i', 'o'))}") // true
println(collection) // [a]
//sampleEnd
}
Retains only the elements in this collection that are contained in the specified collection.
Since Kotlin
1.3Return
true
if any element was removed from the collection, false
if the collection was not modified.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val collection: MutableCollection<Char> = mutableSetOf('a', 'b', 'c')
// Nothing was removed
println("collection.retainAll(listOf('a', 'b', 'c')) is ${collection.retainAll(listOf('a', 'b', 'c'))}") // false
println(collection) // [a, b, c]
println("collection.retainAll(listOf('a', 'e', 'i', 'o')) is ${collection.retainAll(listOf('a', 'e', 'i', 'o'))}") // true
println(collection) // [a]
//sampleEnd
}
Retains only the elements in this collection that are contained in the specified collection.
Since Kotlin
1.8Return
true
if any element was removed from the collection, false
if the collection was not modified.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val collection: MutableCollection<Char> = mutableSetOf('a', 'b', 'c')
// Nothing was removed
println("collection.retainAll(listOf('a', 'b', 'c')) is ${collection.retainAll(listOf('a', 'b', 'c'))}") // false
println(collection) // [a, b, c]
println("collection.retainAll(listOf('a', 'e', 'i', 'o')) is ${collection.retainAll(listOf('a', 'e', 'i', 'o'))}") // true
println(collection) // [a]
//sampleEnd
}
Retains only the elements in this collection that are contained in the specified collection.
Since Kotlin
1.8Return
true
if any element was removed from the collection, false
if the collection was not modified.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val collection: MutableCollection<Char> = mutableSetOf('a', 'b', 'c')
// Nothing was removed
println("collection.retainAll(listOf('a', 'b', 'c')) is ${collection.retainAll(listOf('a', 'b', 'c'))}") // false
println(collection) // [a, b, c]
println("collection.retainAll(listOf('a', 'e', 'i', 'o')) is ${collection.retainAll(listOf('a', 'e', 'i', 'o'))}") // true
println(collection) // [a]
//sampleEnd
}