string + and contat

String s = s1 + s2

Behind the scenes this is translated to:

String s = new StringBuilder(s1).append(s2).toString();

 

tring s = s1.concat(s2);

String creates char[] array that can fit both s1 and s2. Copies s1 and s2 contents to this new array. Actually requires less work then + operator.

 

StringBuilder.append()

Maintains an internal char[] array that grows when needed. No extra char[] is created if the internal one is sufficiently big.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s