LongStream allMatch() in Java


The allMatch() method in the LongStream class returns whether all elements of this stream match the provided predicate.

The syntax is as follows.

boolean allMatch(LongPredicate predicate)

The parameter predicate is a stateless predicate to apply to elements of this stream. The LongPredicate represents a predicate of one long-valued argument.

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

import java.util.stream.LongStream;

The following is an example to implement LongStream allMatch() method in Java.

Example

 Live Demo

import java.util.stream.LongStream;
public class Demo {
   public static void main(String[] args) {
      LongStream longStream = LongStream.of(100L, 150L, 200L, 300L, 400L, 500L);
      boolean res = longStream.allMatch(a -> a > 50L);
      System.out.println("Do all the elements match the predicate? "+res);
   }
}

Output

Do all the elements match the predicate? true

Updated on: 30-Jul-2019

41 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements