How to increment a "number" in a Java 8 lambda expression in a loop?
You can use a static variable :
public class Poubelle {
private static int position = 1;
public static void setPosition (List<PersonMatchInfo> listPersonMatchInfo) {
listPersonMatchInfo.forEach(pmi -> {
pmi.setPosition(position++);
});
}
}
You can use AtomicInteger
, and incrementAndGet
method on it.
Other solution would be int[] position = new int[]{1};
and incrementing position[0]++;