String valueOf vs concatenation with empty string

后端 未结 10 1670
说谎
说谎 2020-11-27 05:05

I am working in Java code optimization. I\'m unclear about the difference between String.valueOf or the +\"\" sign:

int intVar = 1;         


        
10条回答
  •  攒了一身酷
    2020-11-27 05:55

    Even though answers here are correct in general, there's one point that is not mentioned.

    "" + intVar has better performance compared to String.valueOf() or Integer.toString(). So, if performance is critical, it's better to use empty string concatenation.

    See this talk by Aleksey Shipilëv. Or these slides of the same talk (slide #24)

提交回复
热议问题