Difference String and String Buffer

Answer Posted / gangabusi

String is immutable, we can not modify the string objects.
if we can create any string object
Ex: String S="Ganga";
here 'S' is string object created in heap memory.

I Want to add Something to S,
String S="Gangadhar";

Here In heap momory one more object is created for 'S',not
overridden.So that each and every updation String create
one new object in heap.



StringBuffer sb="Ganga"

here 'sb' is stringbuffer object created in heap memory.

I Want to add Something to sb,
StringBuffer sb="Gangadhar";

Here In heap momory 'sb' is overridden.So that each and
every updation StringBuffer create an object in stack.


It is mutable and it is Synchronized.(one thread process at
a time)

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of static methods?

801


What is the list interface in java programming?

796


Can you extend singleton class?

851


What is finalize method?

820


What is the relationship between clipping and repainting under awt?

863


What is difference overloading and overriding?

809


What are the parts of a method?

752


How to disable caching on back button of the browser?

754


How does regex work?

735


What initialize variables?

708


What is array in java?

751


What do the thread?class methods run() and start() do?

784


What are the different http methods?

733


What do you understand by the bean persistent property?

772


What are strings in physics?

770