Top "Java-stream" questions

Use this tag for questions related to the use of the Stream API.

Java 8 method references: provide a Supplier capable of supplying a parameterized result

I'd like to use java.util.Optional.orElseThrow() with an Exception type that asks for a constructor parameter. Something like …

java java-8 java-stream
Adding two Java 8 streams, or an extra element to a stream

I can add streams or extra elements, like this: Stream stream = Stream.concat(stream1, Stream.concat(stream2, Stream.of(element)); …

java concat java-8 java-stream
Java 8: merge lists with stream API

I have the following situation Map<Key, ListContainer> map; public class ListContainer{ List<AClass> lst; } I …

java list java-8 java-stream
Can you split a stream into two streams?

I have a data set represented by a Java 8 stream: Stream<T> stream = ...; I can see how to …

java java-8 java-stream
Reverse a comparator in Java 8

I have an ArrayList and want sort it in descending order. I use for it java.util.stream.Stream.sorted(…

java sorting java-8 comparator java-stream
Is it possible to cast a Stream in Java 8?

Is it possible to cast a stream in Java 8? Say I have a list of objects, I can do something …

java java-8 java-stream
Java 8 NullPointerException in Collectors.toMap

The Java 8 Collectors.toMap throws a NullPointerException if one of the values is 'null'. I don't understand this behaviour, maps …

java nullpointerexception java-8 java-stream collectors
Checking if a list is empty in java 8

I am new to Java8. I have implemented lists and filters. I have done a null check in my code. …

filter java-8 java-stream empty-list
Java8: sum values from specific field of the objects in a list

Suppose to have a class Obj class Obj{ int field; } and that you have a list of Obj instances, i.…

java filter java-8 java-stream
How to check if a Java 8 Stream is empty?

How can I check if a Stream is empty and throw an exception if it's not, as a non-terminal operation? …

java java-8 java-stream