import java.util.Arrays;
import java.util.List;
public class StreamMatchDemo
{
public static void main(String[] args)
{
List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
/*
* Returns:true if either all elements of the stream match the
* provided predicate or the stream is empty, otherwise false
*/
boolean isAllNumbersLargerThanFive = numberList.stream()
.allMatch(i -> i > 5);
System.out.println(isAllNumbersLargerThanFive); // false
/*
* Returns:true if any elements of the stream match the
* provided predicate, otherwise false
*/
boolean hasNumberLargerThanFive = numberList.stream()
.anyMatch(i -> i > 5);
System.out.println(hasNumberLargerThanFive); // true
/*
* Returns:true if either no elements of the stream match the
* provided predicate or the stream is empty, otherwise false
*/
boolean isNoneNumberLargerThanTen = numberList.stream()
.noneMatch(i -> i > 10);
System.out.println(isNoneNumberLargerThanTen); // true
}
}
Outputfalse
true
true
Click the below link to download the code:https://sites.google.com/site/ramj2eev1/home/javabasics/StreamDemo_Ter_Op_match_App.zip?attredirects=0&d=1Github Link:https://github.com/ramram43210/Java/tree/master/BasicJava/StreamDemo_Ter_Op_match_AppBitbucket Link:https://bitbucket.org/ramram43210/java/src/21c94b97f3d45cf2018afb81344804fbe9e1995b/BasicJava/StreamDemo_Ter_Op_match_App/?at=masterSee also: All JavaEE Viedos PlaylistAll JavaEE ViedosAll JAVA EE LinksServlets TutorialAll Design Patterns LinksJDBC TutorialJava Collection Framework TutorialJAVA TutorialKids Tutorial