BinaryOperator
Stay organized with collections
Save and categorize content based on your preferences.
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(Object, Object)
.
Inherited Method Summary
From interface
java.util.function.BiFunction
<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
Returns a BinaryOperator
which returns the greater of two elements
according to the specified Comparator
.
Parameters
comparator |
a Comparator for comparing the two values |
Returns
- a
BinaryOperator
which returns the greater of its operands,
according to the supplied Comparator
Returns a BinaryOperator
which returns the lesser of two elements
according to the specified Comparator
.
Parameters
comparator |
a Comparator for comparing the two values |
Returns
- a
BinaryOperator
which returns the lesser of its operands,
according to the supplied Comparator
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eBinaryOperator\u003c/code\u003e is a functional interface representing an operation on two operands of the same type, producing a result of the same type.\u003c/p\u003e\n"],["\u003cp\u003eIt is a specialization of \u003ccode\u003eBiFunction\u003c/code\u003e where the operands and result share the same type.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eBinaryOperator\u003c/code\u003e provides methods like \u003ccode\u003emaxBy\u003c/code\u003e and \u003ccode\u003eminBy\u003c/code\u003e to find the greater or lesser of two elements based on a \u003ccode\u003eComparator\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe core functionality is inherited from \u003ccode\u003eBiFunction\u003c/code\u003e with the \u003ccode\u003eapply\u003c/code\u003e method to execute the operation.\u003c/p\u003e\n"]]],[],null,["# BinaryOperator\n\npublic interface **BinaryOperator** implements [BiFunction](../../../../reference/java/util/function/BiFunction.html)\\\u003cT, T, T\\\u003e \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.html) for the case where the operands and the result are all of\nthe same type.\n\nThis is a [functional interface](/j2objc/javadoc/jre/reference/java/util/function/package-summary)\nwhose functional method is [BiFunction.apply(Object, Object)](../../../../reference/java/util/function/BiFunction.html#apply(T,%20U)). \n\n##### See Also\n\n- [BiFunction](../../../../reference/java/util/function/BiFunction.html)\n- [UnaryOperator](../../../../reference/java/util/function/UnaryOperator.html) \n\n### Public Method Summary\n\n|--------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static \\\u003cT\\\u003e [BinaryOperator](../../../../reference/java/util/function/BinaryOperator.html)\\\u003cT\\\u003e | [maxBy](../../../../reference/java/util/function/BinaryOperator.html#maxBy(java.util.Comparator\u003c?%20super%20T\u003e))([Comparator](../../../../reference/java/util/Comparator.html)\\\u003c? super T\\\u003e comparator) Returns a [BinaryOperator](../../../../reference/java/util/function/BinaryOperator.html) which returns the greater of two elements according to the specified `Comparator`. |\n| static \\\u003cT\\\u003e [BinaryOperator](../../../../reference/java/util/function/BinaryOperator.html)\\\u003cT\\\u003e | [minBy](../../../../reference/java/util/function/BinaryOperator.html#minBy(java.util.Comparator\u003c?%20super%20T\u003e))([Comparator](../../../../reference/java/util/Comparator.html)\\\u003c? super T\\\u003e comparator) Returns a [BinaryOperator](../../../../reference/java/util/function/BinaryOperator.html) which returns the lesser of two elements according to the specified `Comparator`. |\n\n### Inherited Method Summary\n\nFrom interface [java.util.function.BiFunction](../../../../reference/java/util/function/BiFunction.html) \n\n|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| \\\u003cV\\\u003e [BiFunction](../../../../reference/java/util/function/BiFunction.html)\\\u003cT, T, V\\\u003e | [andThen](../../../../reference/java/util/function/BiFunction.html#andThen(java.util.function.Function\u003c?%20super%20R,%20?%20extends%20V\u003e))([Function](../../../../reference/java/util/function/Function.html)\\\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. |\n| abstract T | [apply](../../../../reference/java/util/function/BiFunction.html#apply(T,%20U))(T t, T u) Applies this function to the given arguments. |\n\nPublic Methods\n--------------\n\n#### public static [BinaryOperator](../../../../reference/java/util/function/BinaryOperator.html)\\\u003cT\\\u003e\n**maxBy**\n([Comparator](../../../../reference/java/util/Comparator.html)\\\u003c? super T\\\u003e comparator)\n\nReturns a [BinaryOperator](../../../../reference/java/util/function/BinaryOperator.html) which returns the greater of two elements\naccording to the specified `Comparator`. \n\n##### Parameters\n\n| comparator | a `Comparator` for comparing the two values |\n|------------|---------------------------------------------|\n\n##### Returns\n\n- a `BinaryOperator` which returns the greater of its operands, according to the supplied `Comparator` \n\n##### Throws\n\n| [NullPointerException](../../../../reference/java/lang/NullPointerException.html) | if the argument is null |\n|-----------------------------------------------------------------------------------|-------------------------|\n\n#### public static [BinaryOperator](../../../../reference/java/util/function/BinaryOperator.html)\\\u003cT\\\u003e\n**minBy**\n([Comparator](../../../../reference/java/util/Comparator.html)\\\u003c? super T\\\u003e comparator)\n\nReturns a [BinaryOperator](../../../../reference/java/util/function/BinaryOperator.html) which returns the lesser of two elements\naccording to the specified `Comparator`. \n\n##### Parameters\n\n| comparator | a `Comparator` for comparing the two values |\n|------------|---------------------------------------------|\n\n##### Returns\n\n- a `BinaryOperator` which returns the lesser of its operands, according to the supplied `Comparator` \n\n##### Throws\n\n| [NullPointerException](../../../../reference/java/lang/NullPointerException.html) | if the argument is null |\n|-----------------------------------------------------------------------------------|-------------------------|"]]