LongStream noneMatch() method in Java


The noneMatch() method of the LongStream class in Java returns whether no elements of this stream match the provided predicate.

The syntax is as follows

boolean noneMatch(LongPredicate predicate)

Here, the parameter predicate is a stateless predicate to apply to elements of this stream. However, LongPredicate in the syntax represents a predicate (boolean-valued function) of one long-valued argument.

To use the LongStream class in Java, import the following package

import java.util.stream.LongStream;

The method returns true if either no elements of the stream match the provided predicate or the stream is empty. The following is an example to implement LongStream noneMatch() method in Java

Example

 Live Demo

import java.util.stream.LongStream;
public class Demo {
   public static void main(String[] args) {
      LongStream longStream = LongStream.of(10L, 20L, 30L, 40L);
      boolean res = longStream.noneMatch(a -> a > 50);
      System.out.println("None of the element match the predicate? "+res);
   }
}

True is returned since none of the element match the predicate

Output

None of the element match the predicate? true

Example

 Live Demo

import java.util.stream.LongStream;
public class Demo {
   public static void main(String[] args) {
      LongStream longStream = LongStream.of(10L, 20L, 30L, 40L, 50, 60L);
      boolean res = longStream.noneMatch(a -> a < 30L);
      System.out.println("None of the element match the predicate? "+res);
   }
}

False is returned since one or more than one element match the predicate

Output

None of the element match the predicate? False

Updated on: 30-Jul-2019

77 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements