contains
operator fun ByteArray.contains(element: Byte): Boolean
operator fun ShortArray.contains(element: Short): Boolean
operator fun IntArray.contains(element: Int): Boolean
operator fun LongArray.contains(element: Long): Boolean
@DeprecatedSinceKotlin("1.4") operator fun FloatArray.contains(
element: Float
): Boolean
@DeprecatedSinceKotlin("1.4") operator fun DoubleArray.contains(
element: Double
): Boolean
operator fun BooleanArray.contains(element: Boolean): Boolean
operator fun CharArray.contains(element: Char): Boolean
Returns true
if element is found in the array.
operator fun <T> Iterable<T>.contains(element: T): Boolean
Returns true
if element is found in the collection.
operator fun <K, V> Map<out K, V>.contains(key: K): Boolean
Checks if the map contains the given key.
This method allows to use the x in map
syntax for checking whether an object is contained in the map.
import kotlin.test.*
import java.util.*
fun main(args: Array<String>) {
//sampleStart
val map: Map<String, Int> = mapOf("x" to 1)
println("map.contains("x") is ${map.contains("x")}") // true
println(""x" in map is ${"x" in map}") // true
println("map.contains("y") is ${map.contains("y")}") // false
println(""y" in map is ${"y" in map}") // false
//sampleEnd
}