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 multi level inheritance in java?

775


what are different ways in which a thread can enter the waiting state? : Java thread

728


What is the role of garbage collector in java?

737


Explain different ways of creating a thread. Which one would you prefer and why?

821


What is codebase?

779


What is a method in coding?

813


Can we override tostring method in java?

731


What is break and continue statement?

812


How many functional interfaces does java 8 have?

822


What do you mean by JVM?

830


Is string an object?

881


What class of exceptions are generated by the java run-time system?

914


What does sprintf return?

822


What is the most important feature of java? What is an interface?

779


Name few java util classes introduced with java 8 ?

728