- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements
To Continue Learning Please Login
Login with Google