Stay organized with collections
Save and categorize content based on your preferences.
BinaryOperator
public
interface
BinaryOperator
implements
BiFunction<T, T, T>
java.util.function.BinaryOperator<T>
|
Represents an operation upon two operands of the same type, producing a result
of the same type as the operands. This is a specialization of
BiFunction
for the case where the operands and the result are all of
the same type.
This is a functional interface
whose functional method is BiFunction.apply(java.lang.Object, java.lang.Object)
.
Summary
Inherited methods |
From interface
java.util.function.BiFunction
default
<V>
BiFunction<T, T, V>
|
andThen(Function<? super R, ? extends V> after)
Returns a composed function that first applies this function to
its input, and then applies the after function to the result.
|
abstract
T
|
apply(T t, T u)
Applies this function to the given arguments.
|
|
Public methods
maxBy
public static BinaryOperator<T> maxBy (Comparator<? super T> comparator)
Returns a BinaryOperator
which returns the greater of two elements
according to the specified Comparator
.
Parameters |
comparator |
Comparator : a Comparator for comparing the two values |
Returns |
BinaryOperator<T> |
a BinaryOperator which returns the greater of its operands,
according to the supplied Comparator |
minBy
public static BinaryOperator<T> minBy (Comparator<? super T> comparator)
Returns a BinaryOperator
which returns the lesser of two elements
according to the specified Comparator
.
Parameters |
comparator |
Comparator : a Comparator for comparing the two values |
Returns |
BinaryOperator<T> |
a BinaryOperator which returns the lesser of its operands,
according to the supplied Comparator |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# BinaryOperator\n\nAdded in [API level 24](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nBinaryOperator\n==============\n\n\n`\npublic\n\n\ninterface\nBinaryOperator\n`\n\n\n`\n\n\nimplements\n\n`[BiFunction](/reference/java/util/function/BiFunction)`\u003cT, T, T\u003e\n\n\n`\n\n|----------------------------------------|\n| java.util.function.BinaryOperator\\\u003cT\\\u003e |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nRepresents an operation upon two operands of the same type, producing a result\nof the same type as the operands. This is a specialization of\n[BiFunction](/reference/java/util/function/BiFunction) for the case where the operands and the result are all of\nthe same type.\n\nThis is a [functional interface](/reference/java/util/function/package-summary)\nwhose functional method is [BiFunction.apply(java.lang.Object, java.lang.Object)](/reference/java/util/function/BiFunction#apply(T,%20U)). \n**See also:**\n\n- [BiFunction](/reference/java/util/function/BiFunction)\n- [UnaryOperator](/reference/java/util/function/UnaryOperator)\n\nSummary\n-------\n\n| ### Public methods ||\n|-----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` static \u003cT\u003e `[BinaryOperator](/reference/java/util/function/BinaryOperator)`\u003cT\u003e` | ` `[maxBy](/reference/java/util/function/BinaryOperator#maxBy(java.util.Comparator\u003c?%20super%20T\u003e))`(`[Comparator](/reference/java/util/Comparator)`\u003c? super T\u003e comparator) ` Returns a [BinaryOperator](/reference/java/util/function/BinaryOperator) which returns the greater of two elements according to the specified `Comparator`. |\n| ` static \u003cT\u003e `[BinaryOperator](/reference/java/util/function/BinaryOperator)`\u003cT\u003e` | ` `[minBy](/reference/java/util/function/BinaryOperator#minBy(java.util.Comparator\u003c?%20super%20T\u003e))`(`[Comparator](/reference/java/util/Comparator)`\u003c? super T\u003e comparator) ` Returns a [BinaryOperator](/reference/java/util/function/BinaryOperator) which returns the lesser of two elements according to the specified `Comparator`. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From interface ` `[java.util.function.BiFunction](/reference/java/util/function/BiFunction)` ` |----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` default \u003cV\u003e `[BiFunction](/reference/java/util/function/BiFunction)`\u003cT, T, V\u003e` | ` `[andThen](/reference/java/util/function/BiFunction#andThen(java.util.function.Function\u003c?%20super%20R,?%20extends%20V\u003e))`(`[Function](/reference/java/util/function/Function)`\u003c? super R, ? extends V\u003e after) ` Returns a composed function that first applies this function to its input, and then applies the `after` function to the result. | | ` abstract T` | ` `[apply](/reference/java/util/function/BiFunction#apply(T,%20U))`(T t, T u) ` Applies this function to the given arguments. | ||\n\nPublic methods\n--------------\n\n### maxBy\n\nAdded in [API level 24](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic static BinaryOperator\u003cT\u003e maxBy (Comparator\u003c? super T\u003e comparator)\n```\n\nReturns a [BinaryOperator](/reference/java/util/function/BinaryOperator) which returns the greater of two elements\naccording to the specified `Comparator`.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|--------------|------------------------------------------------------------------|\n| `comparator` | `Comparator`: a `Comparator` for comparing the two values \u003cbr /\u003e |\n\n| Returns ||\n|---------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|\n| [BinaryOperator](/reference/java/util/function/BinaryOperator)`\u003cT\u003e` | a `BinaryOperator` which returns the greater of its operands, according to the supplied `Comparator` \u003cbr /\u003e |\n\n| Throws ||\n|-------------------------------------------------------------------|-------------------------|\n| [NullPointerException](/reference/java/lang/NullPointerException) | if the argument is null |\n\n### minBy\n\nAdded in [API level 24](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic static BinaryOperator\u003cT\u003e minBy (Comparator\u003c? super T\u003e comparator)\n```\n\nReturns a [BinaryOperator](/reference/java/util/function/BinaryOperator) which returns the lesser of two elements\naccording to the specified `Comparator`.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|--------------|------------------------------------------------------------------|\n| `comparator` | `Comparator`: a `Comparator` for comparing the two values \u003cbr /\u003e |\n\n| Returns ||\n|---------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|\n| [BinaryOperator](/reference/java/util/function/BinaryOperator)`\u003cT\u003e` | a `BinaryOperator` which returns the lesser of its operands, according to the supplied `Comparator` \u003cbr /\u003e |\n\n| Throws ||\n|-------------------------------------------------------------------|-------------------------|\n| [NullPointerException](/reference/java/lang/NullPointerException) | if the argument is null |"]]