W3cubDocs

/Kotlin

isNullOrEmpty

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
fun Array<*>?.isNullOrEmpty(): Boolean

Returns true if this nullable array is either null or empty.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val nullArray: Array<Any>? = null
println("nullArray.isNullOrEmpty() is ${nullArray.isNullOrEmpty()}") // true

val emptyArray: Array<Any>? = emptyArray<Any>()
println("emptyArray.isNullOrEmpty() is ${emptyArray.isNullOrEmpty()}") // true

val array: Array<Char>? = arrayOf('a', 'b', 'c')
println("array.isNullOrEmpty() is ${array.isNullOrEmpty()}") // false
//sampleEnd
}
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
fun <T> Collection<T>?.isNullOrEmpty(): Boolean

Returns true if this nullable collection is either null or empty.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val nullList: List<Any>? = null
println("nullList.isNullOrEmpty() is ${nullList.isNullOrEmpty()}") // true

val empty: List<Any>? = emptyList<Any>()
println("empty.isNullOrEmpty() is ${empty.isNullOrEmpty()}") // true

val collection: List<Char>? = listOf('a', 'b', 'c')
println("collection.isNullOrEmpty() is ${collection.isNullOrEmpty()}") // false
//sampleEnd
}
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
fun <K, V> Map<out K, V>?.isNullOrEmpty(): Boolean

Returns true if this nullable map is either null or empty.

import kotlin.test.*
import java.util.*

fun main(args: Array<String>) {
//sampleStart
val nullMap: Map<String, Any>? = null
println("nullMap.isNullOrEmpty() is ${nullMap.isNullOrEmpty()}") // true

val emptyMap: Map<String, Any>? = emptyMap<String, Any>()
println("emptyMap.isNullOrEmpty() is ${emptyMap.isNullOrEmpty()}") // true

val map: Map<Char, Int>? = mapOf('a' to 1, 'b' to 2, 'c' to 3)
println("map.isNullOrEmpty() is ${map.isNullOrEmpty()}") // false
//sampleEnd
}

© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/is-null-or-empty.html