W3cubDocs

/Kotlin

orEmpty

inline fun <T> Collection<T>?.orEmpty(): Collection<T>

Returns this Collection if it's not null and the empty list otherwise.

inline fun <T> List<T>?.orEmpty(): List<T>

Returns this List if it's not null and the empty list otherwise.

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

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

inline fun <T> Set<T>?.orEmpty(): Set<T>

Returns this Set if it's not null and the empty set otherwise.

inline fun <K, V> Map<K, V>?.orEmpty(): Map<K, V>

Returns the Map if its not null, or the empty Map otherwise.

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/or-empty.html