Java Stream noneMatch() Example

In this tutorial, we will learn Java 8 Stream noneMatch() terminal operation with an example.

The Java Stream noneMatch() method is a terminal operation that will iterate the elements in the stream and return true or false, depending on whether no elements in the stream match the Predicate passed to noneMatch() as the parameter. 

The noneMatch() method will return true if no elements are matched by the Predicate, and false if one or more elements are matched. 

Java Stream noneMatch() Example

Here is a Java Stream noneMatch() 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("john");
        stringList.add("tom");

        Stream<String> stream = stringList.stream();

        boolean noneMatch = stream.noneMatch((element) -> {
            return "Ramesh".equals(element);
        });

        System.out.println("noneMatch = " + noneMatch);

    }
}

Output:

noneMatch = true

Java Stream Methods/APIs Examples


Comments