
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
BinaryOperator Interface in Java
The BinaryOperator interface represents an operation upon two operands of the same type, producing a result of the same type as the operands.
Following are the methods −
Modifier and Type | Method and Description |
---|---|
maxBy(Comparator<? super T> comparator) | Returns a BinaryOperator which returns the greater of two elements according to the specified Comparator. |
minBy(Comparator<? super T> comparator) | Returns a BinaryOperator which returns the lesser of two elements according to the specified Comparator. |
Example
Let us now see an example −
import java.util.function.BinaryOperator; public class Demo { public static void main(String args[]) { BinaryOperator<Integer> operator = BinaryOperator .maxBy( (x, y) -> (x > y) ? 1 : ((x == y) ? 0 : -1)); System.out.println(operator.apply(120, 5)); } }
Output
This will produce the following output −
120
Example
Let us now see another example −
import java.util.function.BinaryOperator; public class Demo { public static void main(String args[]) { BinaryOperator<Integer> operator = (x, y) -> x * y; System.out.println(operator.apply(5, 7)); } }
Output
This will produce the following output −
35
- Related Articles
- How to use BinaryOperator interface in lambda expression in Java?
- Interface in Java
- Nested interface in Java
- Deque interface in Java
- Externalizable Interface in Java
- Marker interface in Java
- Function interface in Java
- IntUnaryOperator Interface in Java
- Serializable Interface in Java
- Why an interface cannot implement another interface in Java?
- Interface enhancements in Java 8
- Set Interface in Java Programming
- SortedMap Interface in Java Programming
- ConcurrentMap Interface in java\n
- Marker interface in Java programming.

Advertisements