Java speed access array index versus temp variable

前端 未结 6 813
情深已故
情深已故 2021-01-17 13:21

What is faster in Java. Accessing an array index directly multiple times, or saving the value of the array index to a new variable and use this for following compution?

6条回答
  •  广开言路
    2021-01-17 14:17

    I would recommend second approach, simply because it is a lot more readable and helps a lot the maintainability.

    Performance gains, except if your array is huge, are really really small.

    Readability gains, on the other hand, are always good to take.

提交回复
热议问题