In this post, we will see how to resolve Java implement accumulator class that provides a Collector Question: A Collector has three generic types: With A being the mutable accumulation type of the reduction operation (often hidden as an implementation ...

In this post, we will see how to resolve Group elements by nested field Question: I have the following domain classes: And I have a list of tasks called tasks. I would like to group Task objects by project’s ids. ...

In this post, we will see how to resolve Java-Stream – How to apply sorting while using Collector groupingBy Question: I’m using Collectors.groupingBy to group may objects into list. Examples are as follows: Output: But my goal is to sort ...

In this post, we will see how to resolve Java Stream – Collecting Parent-objects into a Set after applying flatMap() Question: Is it possible to go back to the parent-object after applying flatmap() operation, and accumulate parent-objects into a set? ...

In this post, we will see how to resolve Are mergeFunction parameters being provided in a deterministic order in the toMap collector? Question: I have two lists that I want to concatenate in a single list and then use Collectors.toMap ...

Question: I have a domain class View: And there’s a list of View objects. Elements having the same id, only differ in one field docId (the second attribute), example: A and I want to convert them into list of aggregated ...

Question: Collectors.toMap throws a NullPointerException if one of the values is null. I don’t understand this behaviour, maps can contain null pointers as value without any problems. Is there a good reason why values cannot be null for Collectors.toMap? Also, ...

Question: I have a List<MyObject> And I need to convert this list into a map Map<String, Map<String, MySumObject>. I’ve created a custom MySumObject class because I need to get a Sum for both amountPaid and amountRemaining from the list of ...

Question: I have a List<MyObject> And I need to convert this list into a map Map<String, Map<String, MySumObject>. I’ve created a custom MySumObject class because I need to get a Sum for both amountPaid and amountRemaining from the list of ...

Question: It is possible to neglect some elements during Collectors.groupingBy or Collectors.partitioningBy? Of course I know I can place a .filter() anywhere in a stream. But my problem is that I have to run a rather complex and expensive evaluation, ...