or
Thanks for your feedback!
Was this page helpful?
Returns this sequence if it's not null
and the empty sequence otherwise.
import kotlin.test.* fun main() { //sampleStart val nullSequence: Sequence<Int>? = null println(nullSequence.orEmpty().toList()) // [] val sequence: Sequence<Int>? = sequenceOf(1, 2, 3) println(sequence.orEmpty().toList()) // [1, 2, 3] //sampleEnd }
xxxxxxxxxx
val nullSequence: Sequence<Int>? = null
println(nullSequence.orEmpty().toList()) // []
val sequence: Sequence<Int>? = sequenceOf(1, 2, 3)
println(sequence.orEmpty().toList()) // [1, 2, 3]
Thanks for your feedback!