How would I turn a for loop into java8 style, but still keeping track of the index and instantiate new objects in the loop?
For example, I currently have a block that pretty much looks for [approve, disapprove..] pattern and filters out the approved one while modifying the disapproved entry. My logic is to check by index. Code is below:
List<Obj> ret = new ArrayList<>();
for (int i = 0; i < res.size() - 1; i++) {
Obj curr = res.get(i);
Obj next = res.get(i + 1);
if (curr.getStatus().equals(APPROVED.toString()) &&
next.getStatus().equals(DISAPPROVED.toString()) {
next.setRate(null);
next.setRateDate(curr.getRateDate());
}
ret.add(curr);
}
How can I turn this into java8 style with say .map() or .filter()?
Thanksss!
EDIT: no more deletion while iterating