I asked this question about doing the same thing with 1D lists, figuring that it would be easy to apply the answers to 2D lists, but it was not.
Basing my code off of Holger's answer, I came up with this solution:
//list is of type ArrayList<List<Integer>>
list.stream()
.map(l -> Stream.concat(
l.subList(0, l.size() - 1).stream().map(i -> i - 2),
Stream.of(l.get(l.size() - 1)).collect(Collectors.toList())
))
.collect(Collectors.toList());
I get the compile-time error Cannot infer type argument(s) for <R> map(Function<? super T,? extends R>)
, however, when I try this.
How is can I perform this function on a 2D list?
Some example input and output:
[[1, 2, 3, 4], [5, 6, 7, 8]]
should output [[-1, 0, 1, 4], [3, 4, 5, 8]]