How to convert an Optionallt;Tgt; into a Streamlt;Tgt;?(如何转换可选的lt;Tgt;进入 Stream lt;Tgt;?)
问题描述
I want to prepend a stream with an Optional. Since Stream.concat
can only concatinate Streams I have this question:
How do I convert an Optional<T> into a Stream<T>?
Example:
Optional<String> optional = Optional.of("Hello");
Stream<String> texts = optional.stream(); // not working
In Java-9 the missing stream()
method is added, so this code works:
Stream<String> texts = optional.stream();
See JDK-8050820. Download Java-9 here.
这篇关于如何转换可选的<T>进入 Stream <T>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!