Combine two lists of same size (and different type) into list of domain objects using java streams

前端 未结 2 1417
我在风中等你
我在风中等你 2021-01-18 18:56

I\'m having two lists of same size ids and results and I want to create new list with domain objects.

List ids = ...

Lis         


        
2条回答
  •  暖寄归人
    2021-01-18 19:57

    I've found a way to do it using guava zip operator.

    List list = Streams.zip(ids.stream(), results.stream(), DomainObject::new)
                                .collect(Collectors.toList());
    

提交回复
热议问题