Java Stream of streamOf (final Iterable iterable)

Here you can find the source of streamOf (final Iterable iterable)

Description

Wrap an iterable in a stream

License

Apache License

Declaration

public static <T> Stream<T> streamOf (final Iterable<? extends T> iterable)
    

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file

import java.util.Iterator;

import java.util.Spliterators;

import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class Main {
    /** Wrap an iterable in a stream */
    public static <T> Stream<T> streamOf(
            final Iterable<? extends T> iterable) {
        return streamOf(iterable.iterator());
    }//from www  .  j  a  va  2 s.  com

    /** Wrap an iterator in a stream */
    public static <T> Stream<T> streamOf(
            final Iterator<? extends T> iterator) {
        return StreamSupport.stream(
                Spliterators.spliteratorUnknownSize(iterator, 0), false);
    }
}

Related

  1. stream(Iterable it)
  2. stream(Iterator iterator)
  3. stream(Object values)
  4. streamEquals(Stream a, Stream b)
  5. streamInt(int max)
  6. streamOf(Iterable it)
  7. streamOf(Iterable iterable)
  8. streamof(Iterable vals)
  9. streamOf(T value)