Having a list of strings, I need to construct a list of objects which are effectively pairs (string, its position in the list). Currently I have such code using
(string, its position in the list)
The easiest way is to stream indices:
List robots = IntStream.range(0, names.size()) .mapToObj(i -> new Robot(i, names.get(i)) .collect(toList());