I have two collections:
List<String> names = ...
List<Long> counts = ...
I know that these two collections are equal and each value at position n in one list matches to the other list.
I want to perform a transformation where as an output I receive:
List<Foo> foos = ...
where Foo
is a record defined as:
record Foo(String name, long count)
For now this is my solution:
List<Foo> foos = IntStream.range(0, names.size())
.mapToObj(i -> new Foo(names.get(i), counts.get(i)))
.collect(Collectors.toList());
My question: Is there an other way to pair and collect Foo objects?