Top "Java-stream" questions

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

How to use Java 8 Collectors groupingBy to get a Map with a Map of the collection?

Imagine these classes class Subject { private int id; private Type type; private String origin; private String name; Subject(int id, …

java-8 java-stream collectors
Java 8 Stream, getting head and tail

Java 8 introduced a Stream class that resembles Scala's Stream, a powerful lazy construct using which it is possible to do …

java scala java-8 java-stream sieve
NullPointerException: element cannot be mapped to a null key

I have read the topic: Collectors.groupingBy doesn't accept null keys But I don't understand how can I apply it …

java java-8 grouping java-stream
Collect stream of EntrySet to LinkedHashMap

I want to collect the stream to a LinkedHashMap<String, Object>. I have a JSON resource that is …

java hashmap java-stream linkedhashmap
java.util.stream.Collectors with EnumSet Stream

I'm trying to use in place of bitmask below is the code public static Set<Amenities> fromBitFlags(int …

java java-8 java-stream enumset
What's the difference between groupingby and mapping in Collectors (Java)?

Take a look at this piece of code. // group by price, uses 'mapping' to convert List<Item> to …

java java-8 java-stream collectors
Using Streams with primitives data types and corresponding wrappers

While playing around with Java8's Streams-API, I stumbled over the following: To convert an array of primitive wrapper classe …

java wrapper java-8 primitive-types java-stream
Why is Files.lines (and similar Streams) not automatically closed?

The javadoc for Stream states: Streams have a BaseStream.close() method and implement AutoCloseable, but nearly all stream instances do …

java stream java-8 java-stream resource-leak
Aggregate List of objects in Java

Do we have any aggregator function in Java to perform the below aggregation? Person { String name; String subject; String department; …

java java-8 aggregate-functions java-stream
How to collect DoubleStream to List

I have the following code: Stream.of("1,2,3,4".split(",")).mapToDouble(Double::valueOf).collect(Collectors.toList()); I want to return List<…

java java-8 java-stream collect