I\'m having two lists of same size ids
and results
and I want to create new list with domain objects.
List ids = ...
Lis
The equivalent of this way with Streams
would be :
List<DomainObject> 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
I've found a way to do it using guava zip
operator.
List<DomainObject> list = Streams.zip(ids.stream(), results.stream(), DomainObject::new)
.collect(Collectors.toList());