Here you can find the source of toStream(Optional
public static <T> Stream<T> toStream(Optional<T> value)
//package com.java2s; //License from project: Open Source License import java.util.Optional; import java.util.stream.Stream; public class Main { /**/*w w w . j av a 2 s .c o m*/ * No longer needed in Java 9 where {@code Optional<T>.stream()} is added. */ public static <T> Stream<T> toStream(Optional<T> value) { if (value.isPresent()) { return Stream.of(value.get()); } else { return Stream.empty(); } } }