Reputation: 57
Lets say i have two generic lists. I want to map one generic values from list into another.
So List <.NameAndSurnameDto> needs to be mapped into another List <.NameAndSurnameDtoTwo>.
What is the best way to do such operation?
Upvotes: 0
Views: 197
Reputation: 18919
List <NameAndSurnameDto> list1; //assuming this is called list1
List <NameAndSurnameDtoTwo> list2 = list1.stream().map(nameAndSurnameDto -> {
return new NameAndSurnameDtoTwo(
... map properties of nameAndSurnameDto to NameAndSurnameDtoTwo
}).collect(Collectors.toList());
Upvotes: 2