isNullOrEmpty
Returns true
if this nullable array is either null or empty.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
//sampleStart
val nullArray: Array? = null
println("nullArray.isNullOrEmpty() is ${nullArray.isNullOrEmpty()}") // true
val emptyArray: Array? = emptyArray()
println("emptyArray.isNullOrEmpty() is ${emptyArray.isNullOrEmpty()}") // true
val array: Array? = 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.3Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val nullList: List? = null
println("nullList.isNullOrEmpty() is ${nullList.isNullOrEmpty()}") // true
val empty: List? = emptyList()
println("empty.isNullOrEmpty() is ${empty.isNullOrEmpty()}") // true
val collection: List? = listOf('a', 'b', 'c')
println("collection.isNullOrEmpty() is ${collection.isNullOrEmpty()}") // false
//sampleEnd
}
Returns true
if this nullable map is either null or empty.
Since Kotlin
1.3Samples
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
val nullMap: Map? = null
println("nullMap.isNullOrEmpty() is ${nullMap.isNullOrEmpty()}") // true
val emptyMap: Map? = emptyMap()
println("emptyMap.isNullOrEmpty() is ${emptyMap.isNullOrEmpty()}") // true
val map: Map? = mapOf('a' to 1, 'b' to 2, 'c' to 3)
println("map.isNullOrEmpty() is ${map.isNullOrEmpty()}") // false
//sampleEnd
}