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
What is thread count in java?
What are drawbacks of singleton class?
what is meant by abstract class?
What is a numeric format?
What are wrapped classes in java programming?
Why do we need wrapper classes?
Which is the best sorting technique in java?
What is a double vs float?
What is java argument list?
Can vector have duplicates in java?
What is byte code and why is it important to java’s use for internet programming?
How do you declare an array in java?
Is singleton set an interval?
Can we define constructor in inner class?
What are the various access specifiers for java classes?