The stream allMatch() method returns whether all elements of this stream match the provided predicate. Its check whether all elements are present or not in the given stream.
boolean allMatch(Predicate super T> predicate)
//Importing required classes import java.util.ArrayList; import java.util.List; import java.util.stream.*; public class AllMatchMethodExample { public static void main(String args[]){ //Declaring List List<
Integer
> intList = new ArrayList<
Integer
>(); intList.add( 6 ); intList.add( 11 ); intList.add( 14 ); intList.add( 7 ); intList.add( 3 ); intList.add( 2 ); intList.add( 16 ); intList.add( 15 ); intList.add( 19 ); boolean result = intList.stream().anyMatch( n -> n%2 == 0 ); System.out.println( result ) } } Output: false
//Importing required classes import java.util.ArrayList; import java.util.List; import java.util.stream.*; public class AllMatchMethodExample { public static void main(String args[]){ //Declaring List List<
Integer
> intList = new ArrayList<
Integer
>(); intList.add(6); intList.add(14); intList.add(2); intList.add(16); boolean result = intList.stream().anyMatch( n -> n%2 == 0 ); System.out.println( result ) } } Output: true