Java 8 uses StringBuilder for Concatenation

An eye opening DZone blog today made me aware Java 8 uses StringBuilder for String concatenation behind the scenes. Remember Strings are immutable and in the past the following would have effectively created 6 different objects for eventual garbage collection. 
 
new String s = ‘String1’ + ‘string2’ + ‘string3’ + ‘string4’ + ‘string5’ 
 
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