Extensions for java.util.Optional

Platform and version requirements: JVM (1.7), JRE8 (1.7)

asSequence

Returns a new sequence for this Optional's value if present, or otherwise an empty sequence. The returned set is serializable (JVM).

fun <T : Any> Optional<out T>.asSequence(): Sequence<T>
Platform and version requirements: JVM (1.7), JRE8 (1.7)

getOrNull

Returns this Optional's value if present, or otherwise null.

fun <T : Any> Optional<T>.getOrNull(): T?
Platform and version requirements: JVM (1.7), JRE8 (1.7)

toCollection

Appends this Optional's value to the given destination collection if present.

fun <T : Any, C : MutableCollection<in T>> Optional<T>.toCollection(
    destination: C
): C
Platform and version requirements: JVM (1.7), JRE8 (1.7)

toList

Returns a new read-only list of this Optional's value if present, or otherwise an empty list. The returned list is serializable (JVM).

fun <T : Any> Optional<out T>.toList(): List<T>
Platform and version requirements: JVM (1.7), JRE8 (1.7)

toSet

Returns a new read-only set of this Optional's value if present, or otherwise an empty set. The returned set is serializable (JVM).

fun <T : Any> Optional<out T>.toSet(): Set<T>

© 2010–2022 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm.optionals/java.util.-optional/index.html