DoubleStream allMatch() method in Java


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

The syntax is as follows −

boolean allMatch(DoublePredicate predicate)

Here, the argument predicate is a stateless predicate to apply to elements of this stream. The DoublePredicate 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 DoubleStream and add some elements −

DoubleStream doubleStream = DoubleStream.of(15.8, 28.7, 35.7, 48.1, 78.9);

Now, check whether the condition is TRUE for elements of the stream −

boolean res = doubleStream.allMatch(num -> num > 10);

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

Example

 Live Demo

import java.util.*;
import java.util.stream.DoubleStream;

public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(15.8, 28.7, 35.7, 48.1, 78.9);
      boolean res = doubleStream.allMatch(num -> num > 10);
      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

58 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements