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

前端 未结 2 1416
我在风中等你
我在风中等你 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:56

    The equivalent of this way with Streams would be :

    List list = IntStream.range(0, ids.size())
                                .mapToObj(i -> new DomainObject(ids.get(i), results.get(i))) 
                                .collect(Collectors.toList());
    

    Or take a look at Iterate two Java-8-Streams

提交回复
热议问题