Top "Java-stream" questions

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

Zipping streams using JDK8 with lambda (java.util.stream.Streams.zip)

In JDK 8 with lambda b93 there was a class java.util.stream.Streams.zip in b93 which could be used …

lambda functional-programming java-8 lazy-evaluation java-stream
In Java, what are the advantages of streams over loops?

I was asked this at an interview and I'm not convinced I gave the best answer I could have. I …

java loops java-8 java-stream
What is difference between Collection.stream().forEach() and Collection.forEach()?

I understand that with .stream(), I can use chain operations like .filter() or use parallel stream. But what is difference …

java collections java-8 java-stream
Limit a stream by a predicate

Is there a Java 8 stream operation that limits a (potentially infinite) Stream until the first element fails to match a …

java java-8 java-stream
New object instantiation when using Java 8 streams

Is there a differnce in using the following contstructs, other than slightly better readability in the latter? someList.stream().map(…

java lambda java-8 java-stream method-reference
Merging two Map<String, Integer> with Java 8 Stream API

I have two (or more) Map<String, Integer> objects. I'd like to merge them with Java 8 Stream API …

java merge java-8 java-stream
Avoid NoSuchElementException with Stream

I have the following Stream: Stream<T> stream = stream(); T result = stream.filter(t -> { double x = …

java java-8 java-stream optional
Check instanceof in stream

I have the following expression: scheduleIntervalContainers.stream() .filter(sic -> ((ScheduleIntervalContainer) sic).getStartTime() != ((ScheduleIntervalContainer)sic).getEndTime()) .collect(Collectors.toList()); ...…

java java-8 java-stream instanceof
Java 8 extract first key from matching value in a Map

Suppose I have a map of given name, surname pairs and I want to find the given name of the …

java lambda java-8 java-stream optional
How can I create a stream from an array?

Currently whenever I need to create stream from an array, I do String[] array = {"x1", "x2"}; Arrays.asList(array).stream(); …

java arrays java-8 java-stream