Spec-Zone.ru › Kotlin 2

remove

kotlin-stdlib/kotlin.collections/HashSet/remove

Требования к платформе и версии: Common (1.0), JS (1.1), Native (1.3), Wasm-JS (1.8), Wasm-WASI (1.8)

@IgnorableReturnValue
expect open 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/-hash-set/remove.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API