Java Utililty Methods Stream Operation

List of utility methods to do Stream Operation

Description

The list of methods to do Stream Operation are organized into topic(s).

Method

Object[][]arrayWrap(final Stream stream)
Produces array of stream's elements wrapped into arrays.
return stream.map(s -> new Object[] { s }).collect(toList()).toArray(new Object[0][]);
ListasList(Stream stream)
Cast stream as list
return stream == null ? null : Arrays.asList(stream.toArray());
StringbuildInvalidArgsError(Stream values, Stream types)
build Invalid Args Error
return "Values [" + values.map(String::valueOf).collect(Collectors.joining(", "))
        + "] cannot be coerced to [" + types.map(Class::getSimpleName).collect(Collectors.joining(", "))
        + "]";
IntStreambytesToIntStream(byte[] bytes)
bytes To Int Stream
return IntStream.range(0, bytes.length).map(i -> bytes[i] & 0xFF);
Streamcast(Stream stream, Class type)
Cast all elements in a stream to a given type, possibly throwing a ClassCastException .
return stream.map(type::cast);
Streamcat(Stream... streams)
Concatenate an array of streams into one stream.
return Arrays.stream(streams).reduce(Stream.empty(), Stream::concat);
StreamcharacterStream2(String s)
character Stream
IntStream is = IntStream.range(0, s.length());
return is.mapToObj(s::charAt);
StringcommaSeparated(Stream stream)
comma Separated
return stream.collect(Collectors.joining(LIST_SEPARATOR));
IntStreamconcat(IntStream... streams)
concat
return Arrays.stream(streams).reduce(IntStream::concat).orElse(IntStream.empty());
Streamconcat(Stream... streams)
Concats any number of Streams not just 2 as in Stream#concat(Stream,Stream) .
return Stream.of(streams).reduce(Stream::concat).orElse(Stream.empty());