what is the main difference between string and stringbuffer?
can you explain it with program?

Answer Posted / ashish ranjan

The main difference between String and StringBuffer is that String is Immutable, which means that we cannot modify the object which is created by the String.
As for Example.
String str = "abc";
now,
str = "abc" + "pqr";
the result is abcpqr. The previous value of str is not modified. It exists in the memory. Java Created new memory for str, which refers abcpqr.

now in case of StringBuffer
StringBuffer str = new StringBuffer("abc");
str.append("pqr");
it modifies in the same object.

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 thread count in java?

543


What are drawbacks of singleton class?

519


what is meant by abstract class?

646


What is a numeric format?

561


What are wrapped classes in java programming?

578






Why do we need wrapper classes?

570


Which is the best sorting technique in java?

517


What is a double vs float?

532


What is java argument list?

516


Can vector have duplicates in java?

505


What is byte code and why is it important to java’s use for internet programming?

591


How do you declare an array in java?

513


Is singleton set an interval?

527


Can we define constructor in inner class?

535


What are the various access specifiers for java classes?

542