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,
Tag: string-concatenation
Fastest way to concatenate multiple strings
I’m working on a function that requires to concatenate multiple strings. Something like 200 – 500 strings. I’m currently using StringBuffer. I wanted to know if this is the fastest way to concatenate multiple strings. I need this method to be as efficient as possible. Answer The StringBuffer with proper capacity new StringBuffer(length) is fastest way to concatenate strings in