Skip to content
Advertisement

Tag: string-concatenation

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,

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

Advertisement