In this tutorial, we will learn Java 8 Stream allMatch() terminal operation with an example.
The Java Stream allMatch() method is a terminal operation that takes a single Predicate as the parameter, starts the internal iteration of elements in the Stream, and applies the Predicate parameter to each element.
If the Predicate returns true for all elements in the Stream, the allMatch() will return true. If not all elements match the Predicate, the allMatch() method returns false.
Java Stream allMatch() Example
Here is a Java Stream allMatch() example:
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args)
{
List<String> stringList = new ArrayList<String>();
stringList.add("Java Guides");
stringList.add("Python Guides");
stringList.add("C Guides");
Stream<String> stream = stringList.stream();
boolean allMatch = stream.allMatch((value) -> { return value.contains("Guides"); });
System.out.println(allMatch);
}
}
Output:
true
Java Stream Methods/APIs Examples
- Java Stream filter() Example
- Java Stream map() Example
- Java Stream flatMap() Example
- Java Stream distinct() Example
- Java Stream limit() Example
- Java Stream peek() Example
- Java Stream anyMatch() Example
- Java Stream allMatch() Example
- Java Stream noneMatch() Example
- Java Stream collect() Example
- Java Stream count() Example
- Java Stream findAny() Example
- Java Stream findFirst() Example
- Java Stream forEach() Example
- Java Stream min() Example
- Java Stream max() Example
- Java Stream reduce() Example
- Java Stream toArray() Example