In java8, how to set the global value in the lambdas foreach block?
You could, of course, “make the outer value mutable” via a trick: public void test() { String[] x = new String[1]; List<String> list = Arrays.asList(“a”, “b”, “c”, “d”); list.forEach(n -> { if (n.equals(“d”)) x[0] = “match the value”; }); } Get ready for a beating by the functional purist on the team, though. Much nicer, … Read more