Class StreamUtils


  • public final class StreamUtils
    extends Object
    Utilities for working with streams
    • Method Detail

      • cast

        public static <T,​S extends T> Stream<S> cast​(Stream<T> stream,
                                                           Class<S> clazz)
        Filter out items in the stream that aren't a subclass of clazz
        Type Parameters:
        T - input of the stream
        S - output of the stream
        Parameters:
        stream - the stream
        clazz - the class to filter and cast on on
        Returns:
        stream of just clazz implementations
      • getIfPresent

        public static <T> Stream<T> getIfPresent​(Stream<Optional<T>> stream)
        Extract optional which are present
        Type Parameters:
        T - content of stream
        Parameters:
        stream - the stream
        Returns:
        stream of non-null (present optionals)
      • append

        public static <T> Stream<T> append​(Stream<T> stream,
                                           T... objects)