Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

What is difference between String & StringBuffer?
String class provides the immutable character 
sequence whereas StringBuffer class objects are 
mutable characters sequence.  The StringBuffer is 
faster than String when performing simple 
concatenations. 

Example:

String s=new String("Hello");
s.toUpperCase();

The String object s is still pointing to "Hello" 
instead  of "HELLO". Here a new string "HELLO" is 
created but did not assinged to any reference 
variable.

But:

StringBuffer sb=new StringBuffer("Hello");

sb.toUpperCase();

The StringBuffer object sb is now pointing to the 
"HELLO".
This is the main difference that string object 
are immutable and string buffer objects are 
mutable.