Top "Java-stream" questions

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

Java 8: Formatting lambda with newlines and indentation

What I would like to achieve with lambda indentation is the following: Multi-line statement: String[] ppl = new String[] { "Karen (F)", "…

java eclipse lambda java-8 java-stream
Why can't I map integers to strings when streaming from an array?

This code works (taken in the Javadoc): List<Integer> numbers = Arrays.asList(1, 2, 3, 4); String commaSeparatedNumbers = numbers.stream() .map(i …

java functional-programming java-8 java-stream
How to split a String into a Stream of Strings?

What is the best method of splitting a String into a Stream? I saw these variations: Arrays.stream("b,l,…

java regex split java-stream
How do I keep the iteration order of a List when using Collections.toMap() on a stream?

I am creating a Map from a List as follows: List<String> strings = Arrays.asList("a", "bb", "ccc"); …

java collections java-8 java-stream
Difference between Java 8 streams and RxJava observables

Are Java 8 streams similar to RxJava observables? Java 8 stream definition: Classes in the new java.util.stream package provide a …

java-8 java-stream rx-java observable
Why is a combiner needed for reduce method that converts type in java 8

I'm having trouble fully understanding the role that the combiner fulfils in Streams reduce method. For example, the following code …

java java-8 java-stream
Why are Java Streams once-off?

Unlike C#'s IEnumerable, where an execution pipeline can be executed as many times as we want, in Java a …

java java-8 java-stream api-design
Is mapToDouble() really necessary for summing a List<Double> with Java 8 streams?

As far as I can tell, the way to sum a List<Double> using Java 8 streams is this: …

java java-8 java-stream
Should I return a Collection or a Stream?

Suppose I have a method that returns a read-only view into a member list: class Team { private List < Player &…

java collections java-8 encapsulation java-stream
Is there any way to reuse a Stream?

I'm learning the new Java 8 features, and while experimenting with streams (java.util.stream.Stream) and collectors, I realized that …

java java-stream reusability