Java 8 - LongBinaryOperator interface example

Posted on December 13, 2016


java.util.function.LongBinaryOperator is a functional interface whose functional method is long applyAsLong(long left, long right). The LongBinaryOperator interface represents an operation that takes two arguments of long type and returns a result of long type.

The following example shows how to use the applyAsLong () method of the LongBinaryOperator interface with lambda expression.

LongBinaryOperatorExample.java

package com.boraji.tutorail.lambda;

import java.util.function.LongBinaryOperator;

/**
 * @author imssbora
 */
public class LongBinaryOperatorExample {
	public static void main(String[] args) {
		
		LongBinaryOperator addition = (a, b) -> a + b;
		LongBinaryOperator subtraction = (a, b) -> a - b;
		LongBinaryOperator multiplication = (a, b) -> a * b;
		LongBinaryOperator divison = (a, b) -> a / b;

		System.out.println(addition.applyAsLong(5, 6));
		System.out.println(subtraction.applyAsLong(10, 6));
		System.out.println(multiplication.applyAsLong(8, 3));
		System.out.println(divison.applyAsLong(8, 4));

	}
}

Output

11
4
24
2