Terminal search operations
public class Example {
public static void main(String[] args) {
Optional<String> first = stream.filter(p).findFirst();
Optional<String> any = stream.parallel().filter(p).findAny();
boolean anyLong = stream.anyMatch(s -> s.length() > 10);
boolean allShort = stream.allMatch(s -> s.length() < 5);
boolean noneEmpty = stream.noneMatch(String::isEmpty);
}
}
public class Example {
public static void main(String[] args) {
// Vacuous truth — surprises people, mathematically correct
Stream.<String>empty().allMatch(s -> false); // true
}
}
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 1 section
- Five classics (practice cells)
Test yourself
Answer these before moving on — recall is what makes it stick.