Here you can find the source of stream(Iterable
Parameter | Description |
---|---|
iterable | The iterable to stream. |
T | The type of the iterable |
public static <T> Stream<T> stream(Iterable<T> iterable)
//package com.java2s; //License from project: Open Source License import java.util.*; import java.util.stream.*; public class Main { /**/*from w w w . j ava 2 s.c om*/ * Converts an Optional value to a stream of 0..1 values * @param optional source optional value * @param <T> The type of the optional value * @return Stream of a single item of type T or an empty stream */ public static <T> Stream<T> stream(Optional<T> optional) { return optional.map(Stream::of).orElseGet(Stream::empty); } /** * Converts an Iterable into a Stream. * @param iterable The iterable to stream. * @param <T> The type of the iterable * @return Stream of the values returned by the iterable */ public static <T> Stream<T> stream(Iterable<T> iterable) { return StreamSupport.stream(iterable.spliterator(), false); } }