Executing a method multiple times using a lambda expression in Java

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(); } 
+6
source share
1 answer

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(0,20).forEach(i -> doSomething()); 
+6
source

Source: https://habr.com/ru/post/984111/


All Articles