Java Stream Operation getStream(Iterable iterable)

Here you can find the source of getStream(Iterable iterable)

Description

Get a sequential Stream from an Iterable .

License

Open Source License

Parameter

Parameter Description
iterable Any iterable

Return

The stream on the elements of the iterable

Declaration

public static <T> Stream<T> getStream(Iterable<T> iterable) 

Method Source Code

//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);
    }
}

Related

  1. firstValue(Stream stream)
  2. flatOptionals(Stream> list)
  3. flattenFeatureStreamToMap( Stream>>> stream)
  4. gcd(IntStream numbers)
  5. getOSIllegalCharacterStream(String path)
  6. getStringStreamFromArray(String... ids)
  7. infiniteParallelStream()
  8. interleave(Stream a, Stream b)
  9. isEmpty(final Stream stream)