remove
Removes a single instance of the specified element from this collection, if the collection contains it.
Since Kotlin
1.0Return
true
if the element has been successfully removed; false
if it was not contained in the collection.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = mutableListOf('a', 'b', 'c')
println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]
// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c]
//sampleEnd
}
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val set = mutableSetOf('a', 'b', 'c')
println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]
// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c]
//sampleEnd
}
Removes a single instance of the specified element from this collection, if the collection contains it.
Since Kotlin
1.1Return
true
if the element has been successfully removed; false
if it was not contained in the collection.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = mutableListOf('a', 'b', 'c')
println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]
// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c]
//sampleEnd
}
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val set = mutableSetOf('a', 'b', 'c')
println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]
// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c]
//sampleEnd
}
Removes a single instance of the specified element from this collection, if the collection contains it.
Since Kotlin
1.0Return
true
if the element has been successfully removed; false
if it was not contained in the collection.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = mutableListOf('a', 'b', 'c')
println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]
// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c]
//sampleEnd
}
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val set = mutableSetOf('a', 'b', 'c')
println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]
// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c]
//sampleEnd
}
Removes a single instance of the specified element from this collection, if the collection contains it.
Since Kotlin
1.3Return
true
if the element has been successfully removed; false
if it was not contained in the collection.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = mutableListOf('a', 'b', 'c')
println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]
// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c]
//sampleEnd
}
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val set = mutableSetOf('a', 'b', 'c')
println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]
// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c]
//sampleEnd
}
Removes a single instance of the specified element from this collection, if the collection contains it.
Since Kotlin
1.8Return
true
if the element has been successfully removed; false
if it was not contained in the collection.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = mutableListOf('a', 'b', 'c')
println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]
// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c]
//sampleEnd
}
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val set = mutableSetOf('a', 'b', 'c')
println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]
// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c]
//sampleEnd
}
Removes a single instance of the specified element from this collection, if the collection contains it.
Since Kotlin
1.8Return
true
if the element has been successfully removed; false
if it was not contained in the collection.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = mutableListOf('a', 'b', 'c')
println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]
// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c]
//sampleEnd
}
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val set = mutableSetOf('a', 'b', 'c')
println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]
// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c]
//sampleEnd
}