isNotEmpty

inline fun <T> Array<out T>.isNotEmpty(): Boolean(source)

Returns true if the array is not empty.

Since Kotlin

1.0

Returns true if the collection is not empty.

Since Kotlin

1.0

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val empty = emptyList()
println("empty.isNotEmpty() is ${empty.isNotEmpty()}") // false

val collection = listOf('a', 'b', 'c')
println("collection.isNotEmpty() is ${collection.isNotEmpty()}") // true 
   //sampleEnd
}

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

Returns true if this map is not empty.

Since Kotlin

1.0

Samples

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

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

val emptyStats: Map = mapOf()
println(totalValue(emptyStats)) // 

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