June 2018
Intermediate to advanced
280 pages
7h 46m
English
The iterator is partially implemented by the usage of the sequence that the streams provide. Java 8 added the forEach method, which receives a consumer as a parameter and behaves just like the previous loop implementation, as can be seen in the following example code:
jshell> List.of(1, 4).forEach(System.out::println)jshell> for(Integer i: List.of(1, 4)) System.out.println(i);
The output for each example is 1 and 4, as expected.
Read now
Unlock full access