Java 8 - IntBinaryOperator interface example

Posted on December 1, 2016


java.util.function.IntBinaryOperator is a functional interface whose functional method is int applyAsInt(int a, int b). The IntBinaryOperator interface represents an operation that takes two arguments of int type and returns a result of int type.

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

IntBinaryOperatorExample.java

package com.boraji.tutorial.lambda;

import java.util.function.IntBinaryOperator;

/**
 * @author imssbora
 */
public class IntBinaryOperatorExample {
	public static void main(String[] args) {
		IntBinaryOperator operator1 = (a, b) -> a + b;
		System.out.println(operator1.applyAsInt(5, 4));

		IntBinaryOperator operator2 = (a, b) -> a - b;
		System.out.println(operator2.applyAsInt(5, 4));

		IntBinaryOperator operator3 = (a, b) -> a * b;
		System.out.println(operator3.applyAsInt(5, 4));
	}
}

Output

9
1
20