isNullOrEmpty

Common
JVM
JS
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
}
Common
JVM
JS
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
}
Common
JVM
JS
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
}