Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a multiplication analogue to Integer::sum?

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.

like image 505
fredoverflow Avatar asked Oct 18 '16 20:10

fredoverflow


1 Answers

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.

like image 175
Rogue Avatar answered Nov 21 '22 18:11

Rogue