How to convert an Optional into a Stream?

后端 未结 6 1602
孤独总比滥情好
孤独总比滥情好 2020-12-05 03:56

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

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 04:13

    In Java-9 the missing stream() method is added, so this code works:

    Stream texts = optional.stream();
    

    See JDK-8050820. Download Java-9 here.

提交回复
热议问题