Skip to content
Advertisement

Tag: benchmarking

Why is String.valueOf faster than String Concatenation for converting an Integer to a String?

This is the converse of the problem “Why is String concatenation faster than String.valueOf for converting an Integer to a String?”. It is not a duplicate. Rather, it stems from this answer with benchmarks asserting that t.setText(String.valueOf(number)) is faster than t.setText(“”+number), and ChristianB’s question as to why that is. Answer String addition results in the compiler creating a StringBuilder instance,

Advertisement