Java.util.function.DoublePredicate interface in Java with ExamplesJDK 8 introduces the DoublePredicate interface. A functional interface called DoublePredicate (java.util.function.DoublePredicate) has three default methods and one abstract method specified in it. A more specialized version of the predicate interface is this particular one. Since it only has one abstract method test (double value) that assesses this predicate using the given input, it is considered basic. The java.util.function package contains this interface's package. It takes a Double object as its input and generates a predicate value according to a given condition. Since it is a functional interface, lambda expressions can also be used. Syntax: The Methods that can be implemented are: 1. test(): A boolean value indicating the result is returned by this function after it has evaluated a conditional check on the double value. Syntax: 2. and(): This function creates a new predicate by applying the AND operation to the object that is currently in use and the object that was passed in as an argument. A default implementation exists for this method. Syntax: 3. negate(): This function flips the test condition, returning the inverse of the current predicate. There is an implementation for this method by default. Syntax: 4. or(): When implementing the OR operation on the object that is now in use and the object that was given as an input, this function returns the newly created predicate. There is a default implementation for this method. Syntax: Example 1:The provided Java program filters a stream of doubles and prints even numbers using the DoublePredicate interface. Implementation: FileName: DoublePredicateEven.java Output: The Even number is : 12.0 The Even number is : 14.0 The Even number is : 16.0 The Even number is : 18.0 The Even number is : 20.0 Example 2:DoublePredicate is used to evaluate conditions on double values, as the Java application demonstrates. It specifies a predicate DB to determine whether a number's square is smaller than 100 and outputs the answer for 10. Implementation: FileName: DoublePredicateEven.java Output: 10 squared is less than 100: false 10 squared is not less than 100: true 9 squared is less than 100 and between 36 and 1000: true 7 squared is less than 100 or between 36 and 1000: true |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India