Skip to content

Tag: java-stream

Java aggregate same objects into one

I’m quite new into programming and got a tricky question. I got an object which has multiple parameters: Every object always has non-null number attribute as well as one of three values-field. So for example, if valueOne is not null, the other two value fields valueTwo and valueThree would be null. So h…

Grouping by query results based on a date using stream API java

I have an entity object with several columns which looks like this: As I use a composite key I have an embeddable class I also have a repository class and I use several request. The following query allow to select database results based on a query on workflow value. String dates have the following format: 202…

Java Stream GroupBy and Reduce

I have an Item class which contains a code, quantity and amount fields, and a list of items which may contain many items (with same code). I want to group the items by code and sum up their quantities and amounts. I was able to achieve half of it using stream’s groupingBy and reduce. The grouping by wor…