[Solved] For Loop with Lambda Expression in JAVA
I think the reason is pretty clear. ints.forEach((i) -> { System.out.print(ints.get(i-1) + ” “); }); Translates approximately to: for (Integer i : ints) { System.out.println(ints.get(i – 1) + ” “); } Which will cause IndexOutOfBoundsExceptions because i refers to the elements of each list, and each of those elements – 1 will give an index … Read more