Difference between String and StringBuffer.

Answer Posted / geetha

String and StringBuilder class stores strings. But when you
cannot change a String object after creating one.
eg: String name = "Prasad";
By saying you cannot change the name object means you cannot
change the value in name object internally. When you change
the name object value to something else, a new String object
is creating in memory and assign the new value.

eg: name = "Prasad Reddy";

A new name object is creating in memory and the value
"Prasad Reddy" is assinging to the newly created space.

But StringBuilder class occupies the same space even if you
change the value.

If you are doing string concatenation StringBuilder class is
far better in performance than String class.

You can use StringBuilder's Append() method to use
concatenation.

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between static binding and dynamic binding?

563


What is the latest version of java?

577


What classes of exceptions may be thrown by a throw statement?

524


What is method in research paper?

569


what is an objects lock and which objects have locks? : Java thread

528






What is the use of object and class classes?

563


what state does a thread enter when it terminates its processing? : Java thread

593


What is meant by 'Class access modifiers'?

550


Do I need to import java.lang package any time? Why?

737


What is null statement?

526


What is the best definition for data?

517


What is the advantage of OOP in java?

657


What is better- service oriented or batch oriented solutions?

1527


What is the difference between scrollbar and scrollpane?

607


Why generics are used in java?

546