Top "Java-stream" questions

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

Java 8 nested loops with streams & performance

In order to practise the Java 8 streams I tried converting the following nested loop to the Java 8 stream API. It …

java performance java-8 nested-loops java-stream
Why is this usage of Stream::flatMap wrong?

I expected to be able to use Stream::flatMap like this public static List<String> duplicate(String s) { …

java java-8 java-stream flatmap
Does the JDK provide a dummy consumer?

I have a need in a block of code to consume 'n' items from a stream then finish, in essence: …

java java-8 java-stream consumer
Java 8 stream short-circuit

Reading up a bit on Java 8, I got to this blog post explaining a bit about streams and reduction of …

java java-8 java-stream short-circuiting
Java stream with method references for instanceof and class cast

Can I convert the following code using method reference? List<Text> childrenToRemove = new ArrayList<>(); group.getChildren().…

java java-8 java-stream method-reference
Java8: select min value 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 java-8 minimum java-stream
Java stream collect to map with multiple keys

I thought I was getting pretty good at Java 8 streams, but then... I have a Foo interface: public interface Foo { …

java key java-stream collect
Multiple null checks in Java 8

I have the below code which is bit ugly for multiple null checks. String s = null; if (str1 != null) { s = …

java lambda java-8 java-stream optional
Java 8 grouping using custom collector?

I have the following class. class Person { String name; LocalDate birthday; Sex gender; String emailAddress; public int getAge() { return birthday.…

java lambda java-8 java-stream collectors
Java Collectors.groupingBy()---is List ordered?

For the Collectors.groupingBy() that returns Map<K,List<T>> is it implied that the List&…

java java-8 java-stream collectors