Here you can find the source of getStream(Iterable
Parameter | Description |
---|---|
iterable | Any iterable |
public static <T> Stream<T> getStream(Iterable<T> iterable)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html *******************************************************************************/ import java.util.Iterator; import java.util.Spliterator; import java.util.Spliterators; import java.util.stream.Stream; import java.util.stream.StreamSupport; public class Main { /**/*from www. ja v a 2s .c om*/ * Get a sequential {@link Stream} from an {@link Iterable}. * * @param iterable * Any iterable * @return The stream on the elements of the iterable */ public static <T> Stream<T> getStream(Iterable<T> iterable) { return StreamSupport.stream(iterable.spliterator(), false); } /** * Get a {@link Stream} from a generic {@link Iterator}. * * Depending on the type of terminal operation used on the stream, the * iterator may or may not have some elements remaining. Be wary if you * re-use the same iterator afterwards. * * @param iterator * The iterator to wrap * @return A stream containing the iterator's elements */ public static <T> Stream<T> getStream(Iterator<T> iterator) { Spliterator<T> spliterator = Spliterators.spliteratorUnknownSize(iterator, 0); return StreamSupport.stream(spliterator, false); } }