Skip to content
Advertisement

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 in parameter a BiConsumer : Then I wanted to

How to collect data to List from Map using java Stream API?

I have map Map<Nominal, Integer> with objects and their counts: And I need to get such a List<Nominal> from it: How can I do this using the Stream API? Answer We can use Collections::nCopies to achieve the desired result: Ideone demo Remark In the demo, I changed the key-type of the Map from Nominal to Object since the definition of

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 sounds

Advertisement