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 finally block?

572


Write a java program to check if a number is prime or not?

541


What are byte codes?

662


Difference between Preemptive scheduling vs. Time slicing?

581


Is 0 an even number?

557






How to disable caching on back button of the browser?

533


What is treemap in java?

561


What is object cloning in Java?

640


if u open login & logout ,how can udisplay the timelogin & logout members ?

1764


What is the difference between the boolean & operator and the && operator in java programming?

572


Why heap memory is called heap?

598


What are the methods of object class ?

571


What is the difference between variable declaration and variable initialization?

512


What comes to mind when someone mentions a shallow copy in java?

670


how are methods defined?

555