DoubleStream anyMatch() method in Java


The anyMatch() method of the DoubleStream class returns whether any elements of this stream match the provided predicate.

The syntax is as follows

boolean anyMatch(DoublePredicate predicate)

Here, the parameter predicate is a stateless predicate to apply to elements of this stream. The DoublePredicate here is a predicate of one double-valued argument.

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

import java.util.stream.DoubleStream;

Create a DoubleStream and add some elements to the stream

DoubleStream doubleStream = DoubleStream.of(67.9, 89.9, 10.5, 95.8, 49.6);

Now, check if any of the elements match the predicate

boolean res = doubleStream.anyMatch(a -> a > 50);

The following is an example to implement DoubleStream anyMatch() method in Java

Example

 Live Demo

import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(67.9, 89.9, 10.5, 95.8, 49.6);
      boolean res = doubleStream.anyMatch(a -> a > 50);
      System.out.println("Do any element match the predicate? "+res);
   }
}

Output

Do any element match the predicate? True

Updated on: 30-Jul-2019

58 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements