Java Stream of toStream(Optional value)

Here you can find the source of toStream(Optional value)

Description

No longer needed in Java 9 where Optional.stream() is added.

License

Open Source License

Declaration

public static <T> Stream<T> toStream(Optional<T> value) 

Method Source Code

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

Related

  1. toStream(final Iterable iterable)
  2. toStream(final Iterable iterable)
  3. toStream(final T source)
  4. toStream(Iterable iterable)
  5. toStream(Iterator iter, boolean parallel)
  6. toStream(T[] array, boolean parallel)
  7. toStreamLine(final Scanner scanner)
  8. toStreamNumber(final Scanner scanner)