contains
Версия Kotlin: 1.0
expect open operator override fun contains(element: E): Boolean
Проверяет, содержится ли указанный элемент в этой коллекции.
Примеры
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val collection: Collection<Int> = listOf(1, 2, 3)
println("1 in collection is ${1 in collection}") // true
println("4 in collection is ${4 in collection}") // false
// Ref does not override equals, so instances compared by reference
class Ref<T>(val value: T)
val r0 = Ref(42)
val refCollection: Collection<Ref<Int>> = listOf(r0)
println("r0 in refCollection is ${r0 in refCollection}") // true
// Ref(42) is a new instance
println("Ref(42) in refCollection is ${Ref(42) in refCollection}") // false
//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/-linked-hash-set/contains.html