DoublePredicate
is a functional interface, which accepts a double
valued argument and returns a boolean value. This interface has the following methods:
test(double value)
and(DoublePredicate other)
negate()
or(DoublePredicate other)
The DoublePredicate
interface is defined in the java.util.function
package. To import the DoublePredicate
interface, we will check the following import statement:
import java.util.function.DoublePredicate;
The test(double value)
method is used to test a given double
valued input on certain evaluations.
boolean test(double value)
double value
: This method accepts a value of type double
.This method returns the result of the evaluation, that is, either True
or False
.
import java.util.function.DoublePredicate;;public class Main{public static void main(String[] args) {// DoublePredicate to check if the double valued argument is evenDoublePredicate isEven = arg -> arg % 2 == 0;// test whether 4 is evenSystem.out.println(isEven.test(4));// test whether 3 is evenSystem.out.println(isEven.test(3));}}
The and(DoublePredicate other)
method is used to chain multiple implementations of the DoublePredicate
together as a short-circuiting and logical AND
operation. If any implementation returns False
during the evaluation, then the subsequent implementations are not invoked.
default DoublePredicate and(DoublePredicate other)
DoublePredicate other
: This is a DoublePredicate
that needs to be evaluated.This method returns a composed predicate.
import java.util.function.DoublePredicate;;public class Main{public static void main(String[] args) {// DoublePredicate to check if the double valued argument is evenDoublePredicate isEven = arg -> arg % 2 == 0;// DoublePredicate to check if the double valued argument is less than 100DoublePredicate isLessThanHundred = arg -> arg < 100;// Composed DoublePredicateDoublePredicate composedPredicate = isEven.and(isLessThanHundred);// test whether 4 is even and less than 100System.out.println(composedPredicate.test(4));// test whether 103 is even and less than 100System.out.println(composedPredicate.test(103));}}
The negate()
method is used to return a DoublePredicate
, which is a negation of the given DoublePredicate
.
default DoublePredicate negate()
This method has no parameters.
This method returns a predicate.
import java.util.function.DoublePredicate;;public class Main{public static void main(String[] args) {// DoublePredicate to check if the double valued argument is evenDoublePredicate isEven = arg -> arg % 2 == 0;// DoublePredicate to get the Opposite of even using the negate methodDoublePredicate isEvenNegate = isEven.negate();// test negation on 4System.out.println(isEvenNegate.test(4));// test negation on 3System.out.println(isEvenNegate.test(3));}}
The or(DoublePredicate other)
method is used to chain multiple implementations of the DoublePredicate
together as a short-circuiting and logical OR
operation. If any implementation returns True
during the evaluation, then the subsequent implementations are not invoked.
default DoublePredicate or(DoublePredicate other)
DoublePredicate other
: This is a DoublePredicate
that needs to be evaluated.This method returns a composed predicate.
import java.util.function.DoublePredicate;;public class Main{public static void main(String[] args) {// DoublePredicate to check if the double valued argument is evenDoublePredicate isEven = arg -> arg % 2 == 0;// DoublePredicate to check if the double valued argument is less than 100DoublePredicate isLessThanHundred = arg -> arg < 100;// Composed DoublePredicateDoublePredicate composedPredicate = isEven.or(isLessThanHundred);// test whether 4 is even and less than 100System.out.println(composedPredicate.test(4));// test whether 103 is even and less than 100System.out.println(composedPredicate.test(103));}}