Skip to content

Tag: stream

Set with Optional

I have this code: I want to replace this code to this: and map this field from myClass to myClass2 How i can do it? Answer Did you mean to use: For mapping I would suggest to read about MapStruct, it is a good tool.

Issues understanding mapMulti

I’m fairly when it comes to Java, and I’ve decided to dig a little into the implementations and uses of the API, especially the Stream API. I’ve made an implementation after thinking I got it right, and it worked. However I realized something that bugged me out. The mapMulti function takes i…

Java Collectors Grouping By

I have an input of integers and I would like to sort all even numbers before all odd ones in ascending order and preserve the odds order. I am pretty sure I can achieve that with collectors and/or downstream collectors, but I am not sure how to do it. I would like to know how can I sort the false

Sort A List of an Object with other object’s method

In the bellow code, with such classes, how can I sort an ArrayList of Students by the score the got from Courses List? I mean how can I sort a List of a specific class by an attribute of this class which is a child of another class. Answer Your “Student” class is confusing. Based on the name, it s…