Which one is faster in Java and why?
Math.max(a,b)(a>b)?a:b(This was asked in an interview.)
Here is the openjdk code for Math.max() in Java:
public static int max(int a, int b) {
return (a >= b) ? a : b;
}
So, the code would probably be (almost) exactly the same speed.
(Lets be honest, if you are worrying about speed improvements at such a low level, you probably have far greater problems in your code.)