orEmpty

actual inline fun <T> Array<out T>?.orEmpty(): Array<out T>(source)

Returns the array if it's not null, or an empty array otherwise.

Since Kotlin

1.0

Samples



import kotlin.test.*
fun main() { 
   //sampleStart 
   val nullArray: Array<Any>? = null
println(nullArray.orEmpty().contentToString()) // []

val array: Array<Char>? = arrayOf('a', 'b', 'c')
println(array.orEmpty().contentToString()) // [a, b, c] 
   //sampleEnd
}