July 2023
Intermediate to advanced
276 pages
6h 55m
English
Given a collection of values, if we want to skip processing a certain number of values or until a certain condition is met, we may use the continue statement along with the if statement in the traditional for loop. In the functional style, we don’t use if or continue. Instead, we can control the iteration using the skip() or dropWhile() functions.
If you like to skip the first four values in the collection and only process the rest, pass the number of values you want to skip to the skip() function, like so:
| | friends.stream() |
| | .skip(4) |
| | .map(String::toUpperCase) |
| | .forEach(System.out::println); |
The call to skip() in the previous example ignores the first four values in the collection from further ...
Read now
Unlock full access