IntStream noneMatch() method in Java

Java 8Object Oriented ProgrammingProgramming

The noneMatch() method in Java returns whether no elements of this stream match the provided predicate. The true boolean value is returned if either no elements of the stream match the provided predicate or the stream is empty.

The syntax is as follows

Boolean noneMatch(IntPredicate predicate)

Here, parameter predicate is the stateless predicate to apply to elements of this stream

Create an IntStream

IntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150);

Here, set a condition that returns whether no elements of this stream match the provided predicate. We are checking for none of the value less than 10

boolean res = intStream.noneMatch(a -> a < 10);

The following is an example to implement IntStream noneMatch() method in Java. It checks whether no element

Example

 Live Demo

import java.util.*;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150);
      boolean res = intStream.noneMatch(a -> a < 10);
      System.out.println(res);
   }
}

Output

true
raja
Published on 27-Mar-2019 07:55:20
Advertisements