Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: StringBuffers
|
Posted: Jan 8, 2003 12:26 PM
|
|
A String is immutable, which means you cannot change it after it is created, whereas a StringBuffer is mutable and can be changed. If you want to build or modify a big string, it is easier and faster to use a StringBuffer. For general purpose use, such as passing parameters, Strings are better.
Note that when you do this:
String s = "Cheese";
s = s + "y";
You are not changing the string to which s originally refered, rather you are creating a new string and s now refers to that one.
With a StringBuffer, you could actually change it:
StringBuffer s = new StringBuffer( "Cheese" );
s.append("y");
|
|