Publish Your Article Here

Java 8 Stream anyMatch(), allMatch() and noneMatch() example.

Stream.anyMatch() returns whether any elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result. If the stream is empty then false is returned and the predicate is not evaluated.

Stream.allMatch() returns whether all elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result.

Stream.noneMatch() returns whether no elements of this stream match the provided predicate.

package com.java2novice.streams;

import java.util.ArrayList;
import java.util.List;

import com.java2novice.lambda.Employee;

public class StreamMatchEx {

        public static void main(String a[]) {

                List<Employee> empList = new ArrayList<>();
                empList.add(new Employee("Nataraja G", "Accounts", 8000));
                empList.add(new Employee("Nagesh Y", "Admin", 15000));
                empList.add(new Employee("Vasu V", "Security", 2500));
                empList.add(new Employee("Amar", "Admin", 12500));

                boolean result =>emp.getAccount().matches("Admin"));

                result =>emp.getAccount().matches("Admin"));

                result =>emp.getAccount().matches("Admin"));

package com.java2novice.lambda;

public class Employee {

        private String name;
        private String account;
        private Integer salary;

        public Employee(String name, String account, Integer salary) {
       = name;
                this.account = account;
                this.salary = salary;

        public String toString() {

                return "name: "+ +" | account: "+ this.account +" | salary: "+this.salary;

        public String getName() {
                return name;

        public void setName(String name) {
       = name;

        public String getAccount() {
                return account;

        public void setAccount(String account) {
                this.account = account;

        public Integer getSalary() {
                return salary;

        public void setSalary(Integer salary) {
                this.salary = salary;

<< Previous Program | Next Program >>

Java 8 Streams Examples

  1. How Java 8 Streams work?
  2. Java 8 Streams parallelism introduction.
  3. Explain non-interference behavior of Java 8 Streams.
  4. Create Java 8 Stream using Stream.of() method example.
  5. Create Java 8 Stream using List example.
  6. Create Java 8 Stream using Stream.generate() method.
  7. Java 8 Stream.filter() example.
  8. Java 8 example.
  9. Java 8 Stream flatmap method example.
  10. Java 8 Stream peek method example.
  11. Java 8 Stream distinct method example.
  12. Java 8 Stream sorted method example.
  13. Java 8 Stream limit method example.
  14. Java 8 Stream forEach method example.
  15. Java 8 Stream toArray method example.
  16. Java 8 Stream reduce method example.
  17. Java 8 Stream collect method example.
  18. Java 8 Stream concat method example.
  19. Java 8 Stream anyMatch(), allMatch() and noneMatch() example.
  20. Java 8 Stream findFirst(), findAny() example.
  21. Primitive type Stream example.
Knowledge Centre
Interface and its usage
Interface is similar to a class which may contain method's signature only but not bodies and it is a formal set of method and constant declarations that must be defined by the class that implements it. Interfaces are useful for declaring methods that one or more classes are expected to implement, capturing similarities between unrelated classes without forcing a class relationship and determining an object's programming interface without revealing the actual body of the class.
Famous Quotations
Discipline is just choosing between what you want now and what you want most.
-- Unknown Author

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2024 by Nataraja Gootooru. All Rights Reserved.