isNotEmpty

Common
JVM
JS
Native
1.0
fun <T> Array<out T>.isNotEmpty(): Boolean
(source)
fun ByteArray.isNotEmpty(): Boolean
(source)
fun ShortArray.isNotEmpty(): Boolean
(source)
fun IntArray.isNotEmpty(): Boolean
(source)
fun LongArray.isNotEmpty(): Boolean
(source)
fun FloatArray.isNotEmpty(): Boolean
(source)
fun DoubleArray.isNotEmpty(): Boolean
(source)
fun BooleanArray.isNotEmpty(): Boolean
(source)
fun CharArray.isNotEmpty(): Boolean
(source)

Returns true if the array is not empty.

Common
JVM
JS
Native
1.0
fun <T> Collection<T>.isNotEmpty(): Boolean
(source)

Returns true if the collection is not empty.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val empty = emptyList<Any>()
println("empty.isNotEmpty() is ${empty.isNotEmpty()}") // false

val collection = listOf('a', 'b', 'c')
println("collection.isNotEmpty() is ${collection.isNotEmpty()}") // true
//sampleEnd
}
Common
JVM
JS
Native
1.0
fun <K, V> Map<out K, V>.isNotEmpty(): Boolean
(source)

Returns true if this map is not empty.

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

fun main(args: Array<String>) {
//sampleStart
fun totalValue(statisticsMap: Map<String, Int>): String =
    when {
        statisticsMap.isNotEmpty() -> {
            val total = statisticsMap.values.sum()
            "Total: [$total]"
        }
        else -> "<No values>"
    }

val emptyStats: Map<String, Int> = mapOf()
println(totalValue(emptyStats)) // <No values>

val stats: Map<String, Int> = mapOf("Store #1" to 1247, "Store #2" to 540)
println(totalValue(stats)) // Total: [1787]
//sampleEnd
}