Java.util.function.DoubleBinaryOperator interface with ExamplesIn Java8, the DoubleBinaryOperator interface came into existence. It returns a double value as the final result of an operation on two double values that it represents. It can be used as a method reference or as a lambda expression because it is a functional interface. Generally, it is used in circumstances where the user must not be involved in the process. The Method that can be implemented is: applyAsDouble(): This function takes two double values, performs the required operation, and returns the result as a double. Syntax: Example 1:The Java implementation mentioned below shows how to add elements in a DoubleStream by using streams and functional interfaces. Implementation: FileName: SumOperator.java Output: The total sum of the elements is: 65.0 Example 2:Using two double values, p, and q, the supplied Java program shows how to execute fundamental arithmetic operations on them using the DoubleBinaryOperator interface. Each operation (addition, subtraction, multiplication, division, and modulo division) has a DoubleBinaryOperator lambda expression defined for it. Implementation: FileName: BinaryOperators.java Output: The sum is p + q = 100.0 The difference is p - q = 40.0 The product is p * q = 2100.0 The division is p / q = 2.3333333333333335 The modulo division is p % q = 10.0 |
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