I am trying to do a map
operation on a List<Integer>
:
list.stream().map(i -> i - 2).collect(Collectors.toList());
Instead of performing the operation on the last element of the list, I would like it to just be passed through. ...Collectors.toList()).add(i)
doesn't work, of course, because i
is out of scope.
For example, the input list [1, 2, 3, 4]
should output [-1, 0, 1, 4]