Skip to content
Advertisement

Java functional programming: create list of object from a different list

I’d like to convert to funcional programming the following method:

JavaScript

Someone could show me how can I create an instance of an object based on the current list using functional programming?

Thank you

Advertisement

Answer

You should just use map and collect methods of the stream:

JavaScript

Though it would be better to provide better copy constructor in PayrollEntry:

JavaScript

Then it is possible to use the constructor as a method reference:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement