What is the easiest and fastest way to execute a block of code multiple times using a lambda expression in Java 8? For example, code that replaces the following:
for (int i = 0; i < 20; i ++) { doSomething(); }
You can use IntStream.range , but I donβt see much advantage in this approach to the loop that you are already using.
IntStream.range
IntStream.range(0,20).forEach(i -> doSomething());
Source: https://habr.com/ru/post/984111/More articles:Best way to safely name a new one in this trivial example? - c ++RegExp not working on reading HTML file - javascriptConstant Injection Using Custom Annotation - javaHow to make the meteor helper inactive? - javascriptConstants and annotations - javaGrepping or filtering the Xcode "Devices" console - iosHow to test sns locally in an IDE, for example Intellij (for unit tests) - amazon-snsHow to iterate C ++ sets in Cython? - c ++"error: expected element found by let" - rustWhat does the "expected element found let" mean? - rustAll Articles