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 here’s my problem: The SampleObject is referenced in

Using a predefined lambda as an argument in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 11 days ago. Improve this question So i’m trying to pass this test: I’m having a really hard time understanding how to create a method count that can take the lambda

Retrieve word(s) from characters using map

I am trying to understand Collections and Stream. I have split the sentence below and kept the position of each letter (I ignored space/blank): “Hello Word!” Results: [H, e, l, l, o, , W, o, r, d, !] (charsList) {!=[10], r=[8], d=[9], e=[1], W=[6], H=[0], l=[2, 3], o=[4, 7]} (charsIndex) How can I sort the characters and rebuild my word

Java Stream – Collecting Parent-objects into a Set after applying flatMap()

Is it possible to go back to the parent-object after applying flatmap() operation, and accumulate parent-objects into a set? I have an UnifiedOfferEntity with set of other entity objects as a field: I would like to filter through fields of the parent-object (UnifiedOfferEntity) like this: And then I would like to examine the nested collection, filter through child-objects (ContractDetailsEntity): And

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: 2022-04-05 (YYYY-MM-dd). My issue is

Convert a List of JSON-objects input into a nested Map

I have a String input in the following format: Input String: [{ “id”:”1″, “name”:”A”, “address”:”St 1″},{ “id”:”2″, “name”:”B”, “address”:”St 2″}, …] And I want to be able to convert this to a Map<String, Map<String, String>> format. So, something like: Required Output Format: {1: {id:1, name:”A”, address: “St 1″} 2: {id:2, name:”B”, address: “St 2”}} I created a class to help

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 worked, but the