I have the following problem. I have an integer position that starts at 1 and increases every time a particular person from txt is in a certain position in xml. If I use the classic iteration with foreach for (PersonMatchInfo pmi : personMatchInfo) , this works, but my older one asked me to do foreach with Java 8, and this type of iteration only works with final variables. How can I increment an integer in a new Java 8 loop? Thanks.
int position = 1; personMatchInfo.forEach(pmi ->{ if (!stopwatch1.isStarted()) { stopwatch1.start(); } else if (stopwatch1.isStarted()) { } if (pmi.getPersonName().equals(e.getValue())) { positionMap.put(position, positionMap.get(position) + 1); break; } else { position++; } });
source share