I have an instance of OptionalLong
. But one of my libraries requires an Optional
as a parameter.
How can I convert my Option
One more possibility, though only from JDK 9 is via the new OptionalLong.stream()
method, which returns a LongStream
. This can then be boxed to a Stream
:
OptionalLong optionalLong = OptionalLong.of(32);
Optional optional = optionalLong.stream().boxed().findFirst();
With JDK 8 something similar can be done, by stepping out to the Streams utility class in Guava:
Optional optional = Streams.stream(optionalLong).boxed().findFirst();