Quantcast
Channel: In detail, how does the 'for each' loop work in Java? - Stack Overflow
Viewing all articles
Browse latest Browse all 61

Answer by Alexander Drobyshevsky for In detail, how does the 'for each' loop work in Java?

$
0
0

An alternative to forEach in order to avoid your "for each":

List<String> someList = new ArrayList<String>();

Variant 1 (plain):

someList.stream().forEach(listItem -> {    System.out.println(listItem);});

Variant 2 (parallel execution (faster)):

someList.parallelStream().forEach(listItem -> {    System.out.println(listItem);});

Viewing all articles
Browse latest Browse all 61

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>