Which one is faster in Java and why?
Math.max(a,b)
(a>b)?a:b
(This was asked in an interview.)
The original question doesn't specify the type of the arguments. This matters because the definition of max (and min) for floating point arguments is more complex. For floating point (double or float) the Math.max method is likely to be slower, but it also may return a different result if one of the arguments is NaN.