Top "Java-stream" questions

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

Is there a concise way to iterate over a stream with indices in Java 8?

Is there a concise way to iterate over a stream whilst having access to the index in the stream? String[] …

java java-8 java-stream
Does Java SE 8 have Pairs or Tuples?

I am playing around with lazy functional operations in Java SE 8, and I want to map an index i to …

java lambda functional-programming java-8 java-stream
Filter Java Stream to 1 and only 1 element

I am trying to use Java 8 Streams to find elements in a LinkedList. I want to guarantee, however, that there …

java lambda java-8 java-stream
Collectors.toMap() keyMapper -- more succinct expression?

I'm trying to come up with a more succinct expression for the "keyMapper" function parameter in the following Collectors.toMap() …

java collections lambda java-8 java-stream
How to add elements of a Java8 stream into an existing List

Javadoc of Collector shows how to collect elements of a stream into a new List. Is there an one-liner that …

java java-8 java-stream collectors
Sorting a list with stream.sorted() in Java

I'm interested in sorting a list from a stream. This is the code I'm using: list.stream() .sorted((o1, o2)…

java list sorting java-stream
Java 8 stream reverse order

General question: What's the proper way to reverse a stream? Assuming that we don't know what type of elements that …

java list sorting java-8 java-stream
Custom thread pool in Java 8 parallel stream

Is it possible to specify a custom thread pool for Java 8 parallel stream? I can not find it anywhere. Imagine …

java concurrency parallel-processing java-8 java-stream
Java 8 Streams: multiple filters vs. complex condition

Sometimes you want to filter a Stream with more than one condition: myList.stream().filter(x -> x.size() &…

java lambda filter java-8 java-stream
Java 8 Stream and operation on arrays

I have just discovered the new Java 8 stream capabilities. Coming from Python, I was wondering if there was now a …

java arrays java-8 java-stream