isNullOrEmpty

inline fun Array<*>?.isNullOrEmpty(): Boolean(source)

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

Since Kotlin

1.3

Samples

import kotlin.test.*

fun main() { 
   //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
}

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

Since Kotlin

1.3

Samples

import kotlin.test.*

fun main() { 
   //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
}

inline fun <K, V> Map<out K, V>?.isNullOrEmpty(): Boolean(source)

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

Since Kotlin

1.3

Samples

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

fun main() { 
   //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
}