Java Stream Issue
I have a problem about writing a java stream by filtering multiple conditions , groupby multiple condition (if possible) and calculating the sum value
I store the values as
Map<String(pId),List<Person>>
Here is my Person class shown below
Here is the list
What I want to do is to get this result.
Here is group dto shown below
Here is my dto shown below.
Here is the code snippet but I cannot complete it.
How can I do that?10 Replies
Hey, @direct_x_34!
Please remember to
/close
this post once your question has been answered!Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Value should be Object not int.
I just tested it but it didn't work.
How can I fix it?
@Spoon
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I'm getting incorrect count totalPerson because I'm not taking into account person id.
I'm treating each DTO in your code as representing a distinct Person which is not true
How can I do that?
I think the way to solve the issue.Firstly I can create an intermediate object maintaining a set of person id to accumulate the Person instances. And then turn these objects into DTO by using the size of their Sets of ids as the person count. However, I have no idea how to implement it for my issue which I mentioned before.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Here is the example list shown below.
What I want to get this result as you can see below. I got this result as you can see. @Spoon I cannot get the right values of total persons @Andrew Hi, I think you can help me fix my issue regarding java stream. I cannot get the right values of total persons
What I want to get this result as you can see below. I got this result as you can see. @Spoon I cannot get the right values of total persons @Andrew Hi, I think you can help me fix my issue regarding java stream. I cannot get the right values of total persons
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
@Andrew Who can I ask it?
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.