dzefrej0
dzefrej0

Reputation: 57

How to map generic list into another generic list?

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

Answers (1)

Panagiotis Bougioukos
Panagiotis Bougioukos

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

Related Questions