Convert list from one type to another using lambda expressions in Java



This example shows how to convert a list of a certain type of objects to a list with another type of objects using lambda expressions (available from Java 8).

First we create to classes to work with, Employee and Person. The employee has got three attributes and the Person class has just one that matches one the attributes from Employee, the name.

Then we create an ArrayList of employee objects and add one object to it. Finally we do the conversion like this:







Search for more Java info on this site here:
Custom Search


Please type any questions here.