A Techno Blog, mainly about Java

StringBuffer and String

Link: AlwaysUseStringBufferMisconception

Webpshere Best Practices: "String concatenation is the textbook bad practice that illustrates the adverse performance impact of creating large numbers of temporary Java objects. Because Strings are immutable objects, String concatenation results in temporary object creation that increases Java garbage collection and consequently CPU utilization as well. The textbook solution is to use java.lang.StringBuffer instead of string concatenation."

Take from the The Server Side

Being immutable means that that once Strings are created they can not be changed.  Operations that appear to modify String objects actually generate completely new ones.

The creation of new String objects occurrs for:

  • overlaoded mathematical operations
  • concat
  • replace
  • substring
  • trim


April 4, 2005 - Posted by | J2EE

No comments yet.

Leave a Reply

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

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

%d bloggers like this: