Since Java 8, the Integer
class has a static sum
method that adds two integers:
public static int sum(int a, int b) {
return a + b;
}
I can pass this method to higher-order functions via Integer::sum
which I find more readable than (a, b) -> a + b
.
Is there a similar static method for multiplication, so I don't have to write (a, b) -> a * b
? I couldn't find one in the Integer
class.
You can make it yourself:
public static int mult(int a, int b) {
return a * b;
}
This might seem obvious in retrospect but outside of that I don't believe there's actually a jdk-included method which multiplies for you, except for Math#multiplyExact
(Math::multiplyExact
), though this might be more than you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With