what is the difference between the String and StringBuffer class...?
@nayanimuralidhar (93)
India
January 29, 2009 5:42am CST
While i am doing the java programs i have this doubt.then these two are same but having some difference .i have to find that difference string also can store some characters and some values but what about the StrinBuffer.
3 responses
@neerajpandey_13 (1765)
• India
5 Apr 09
We can modify the StringBuffer class whereas String class cannot be modified. Only instance of string class can be modified.
@silvermoney (241)
• India
29 Jan 09
String objects are constants and immutable where as StringBuffer objects are not.StringBuffer Class supports growable and modifiable string where as String class
supports constant strings. Strings once created we cant modify them. Any such attempt will lead to the creation of new strings.Where as StingBuffer objects after creation also can be able to delete oo append any characteres to it.String values are resolved at run time where as StringBuffer valuesc are resolved at compile time.So if you know the exact size of the string to be appended it is better to go for String objects.
@anjaiah_msc (3)
• India
29 Jan 09
string and sttringbuffer both are storing characters.
but main difference is if we adding another string in string new object is created and then concated string is stored.
but in case of string same object string is add. and stringbuffer is synchronized.
so stringbuilder is implemented.