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

intmapElementsSizes(IntStream intStream)
map Elements Sizes
OptionalInt n = intStream.reduce((a, b) -> (a == -1) ? -1 : (b == 1) ? a : (a == b) ? a : (a == 1) ? b : -1
);
return n.isPresent() ? n.getAsInt() : 1;
floatmaximum(final Stream stream)
Get Maximum X position of TextPosition List .
return stream.max(Float::compare).get().floatValue();
longmaxLong(Stream stream)
Returns the highest value on a stream of longs
return stream.mapToLong(Long::valueOf).max().getAsLong();
intmaxStringLength(Stream stringStream)
max String Length
return stringStream.mapToInt(String::length).max().getAsInt();
StringmkString(Stream items, String prefix, String delimiter, String suffix)
mk String
StringJoiner joiner = new StringJoiner(delimiter);
items.forEach(joiner::add);
return prefix + joiner.toString() + suffix;
StreamnullableStreamOf(Collection nullableCollection)
nullable Stream Of
if (nullableCollection == null) {
    return Stream.empty();
return nullableCollection.stream();
StreamofType(Stream stream, Class type)
Keep only those elements in a stream that are of a given type.
return stream.filter(type::isInstance).map(t -> (U) t);
Streamopt2stream(Optional opt)
Turns an Optional into a Stream of length zero or one depending upon whether a value is present.
return opt.map(Stream::of).orElseGet(Stream::empty);
StreamoptionalToStream(final Optional optional)
optional To Stream
if (optional.isPresent())
    return Stream.of(optional.get());
return Stream.of();
StreamoptionalToStream(Optional optional)
optional To Stream
return optional.map(Stream::of).orElseGet(Stream::empty);