Top "Java-stream" questions

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

Java 8's streams: why parallel stream is slower?

I am playing with Java 8's streams and cannot understand the performance results I am getting. I have 2 core CPU (…

java performance parallel-processing java-8 java-stream
How to insert a counter into a Stream<String> .forEach()?

FileWriter writer = new FileWriter(output_file); int i = 0; try (Stream<String> lines = Files.lines(Paths.get(input_file))) { …

java foreach java-stream line-numbers
How to use collect call in Java 8?

Lets say we have this boring piece of code that we all had to use: ArrayList<Long> ids = …

java java-8 java-stream collect
sorting Lists after groupingBy

I am wondering, if there is already an implemented feature in streams (or Collectors) which has sorted Lists as values. …

java sorting java-stream groupingby
Why does Iterable<T> not provide stream() and parallelStream() methods?

I am wondering why the Iterable interface does not provide the stream() and parallelStream() methods. Consider the following class: public …

java java-8 java-stream iterable
Static context cannot access non-static in Collectors

I have group of students. First I want to group them by the marks. Then I want to further group …

java java-8 java-stream method-reference collect
When should I use streams?

I just came across a question when using a List and its stream() method. While I know how to use …

java java-8 java-stream
How do I create an empty Stream in Java?

In C# I would use Enumerable.Empty(), but how do I create an empty Stream in Java?

java java-stream enumerable
Nested lists with streams in Java8

I have a list of objects A. Each object A in this list contains list of object B and the …

java list java-8 java-stream nested-loops