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

Reverse order of For Each loop

It’s not possible to loop backwards using the for each loop syntax. As an alternative you can use a For i = a To 1 Step -1 loop: Sub reverseForEach() Dim i As Long, rng As Range Set rng = ActiveSheet.Range(“A1:B2”) For i = rng.Cells.Count To 1 Step -1 Debug.Print rng.item(i).Address ‘ Or shorthand rng(i) … Read more

Is the ranged based for loop beneficial to performance?

The Standard is your friend, see [stmt.ranged]/1 For a range-based for statement of the form for ( for-range-declaration : expression ) statement let range-init be equivalent to the expression surrounded by parentheses ( expression ) and for a range-based for statement of the form for ( for-range-declaration : braced-init-list ) statement let range-init be equivalent … Read more