+ 3
Guys,why we use string buffer in java?
3 odpowiedzi
+ 5
string is immutable.so we can't perform some operation on strings,so overcome that problem we use string buffer it is mutable.
am,I correct guys?
+ 3
String buffer is mutable.
Similar to why we might use arraylists instead of arrays, the string buffer is designed to be quick performance wise when adding (appending) to the string.
So, if you ever feel the need to constantly change the value of a string, it may be better to use string buffer.
As stated in many other sources, it's commonly used for String concatenation.
Might be nice for large toStrings().
+ 1
It's not that we can't, it's for performance.
Example/
String a = "a";
a += "b";
This is creating a new string with the value of ab.