What is the easiest and quickest way to execute a code block multiple times using a lambda expression in Java 8? For example, a code that will replace the following:
for (int i = 0; i < 20; i ++) {
doSomething();
}
You can use an IntStream.range
, but I don't see much advantage to this approach over the loop you are already using.
IntStream.range(0,20).forEach(i -> doSomething());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With