Java String Concatenation and Performance

Java String Concatenation and Performance ~ Joey’s Scribble’s. “The quick and dirty way to concatenate strings in Java is to use the concatenation operator (+). This will yield a reasonable performance if you need to combine two or three strings (fixed-size). But if you want to concatenate n strings in a loop, the performance degrades in multiples of n.” An article that compares the speed of  4 different ways to concatenating Strings in Java.  Using  StringBuilder is clearly the fastest but it is interesting to see the range of differences. The comments to the article also mention when StringBuffer should be preferred.

via Dz0ne

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: