Is Math.max(a,b) or (a>b)?a:b faster in Java?

后端 未结 7 1555
深忆病人
深忆病人 2020-12-03 20:59

Which one is faster in Java and why?

  1. Math.max(a,b)
  2. (a>b)?a:b

(This was asked in an interview.)

相关标签:
7条回答
  • 2020-12-03 21:28

    If I had asked such a question in an interview, I would have expected the candidate to tell me that the two expressions may not give the same result for all possible types of a and b.

    0 讨论(0)
提交回复
热议问题