isNotEmpty

inline fun <T> Array<out T>.isNotEmpty(): Boolean
inline fun ByteArray.isNotEmpty(): Boolean
inline fun ShortArray.isNotEmpty(): Boolean
inline fun IntArray.isNotEmpty(): Boolean
inline fun LongArray.isNotEmpty(): Boolean
inline fun FloatArray.isNotEmpty(): Boolean
inline fun DoubleArray.isNotEmpty(): Boolean
inline fun BooleanArray.isNotEmpty(): Boolean
inline fun CharArray.isNotEmpty(): Boolean

Returns true if the array is not empty.


inline fun <T> Collection<T>.isNotEmpty(): Boolean

Returns true if the collection is not empty.

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val empty = emptyList<Any>()
assertFalse(empty.isNotEmpty())

val collection = listOf('a', 'b', 'c')
assertTrue(collection.isNotEmpty()) 
   //sampleEnd
}

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

Returns true if this map is not empty.

Samples

import samples.*
import kotlin.test.*
import java.util.*
fun main() { 
   //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()
assertPrints(totalValue(emptyStats), "<No values>")

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