удалить
Требования к платформе и версии: Common (1.0), JS (1.1), JVM (1.0), Native (1.3), Wasm-JS (1.8), Wasm-WASI (1.8)
expect abstract override fun remove(element: E): Boolean
Удаляет один экземпляр указанного элемента из этой коллекции, если коллекция содержит его.
Возвращаемое значение
true, если элемент был успешно удалён; false, если он не содержался в коллекции.
Примеры
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
}
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/remove.html