Fastest way to concatenate multiple strings

Tags: , , , ,

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.


The StringBuffer with proper capacity new StringBuffer(length) is fastest way to concatenate strings in J2ME.

But before doing optimizations I would suggest you to profile application and find real place that require it.

If the string concatenation is issue. I would think a little bit different. I hardly believe that you’re going to display this data to user. Most probably you’re going to send it over the network. I would modify network protocol between my server and client (if you have this opportunity) to some raw format protocol and would write strings to OtputStream one by one without concatenation them to XML, JSON, etc

Source: stackoverflow