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 the size of string?
What is serialization in java?
Why do we need strings in java?
What happens if we don’t override run method ?
What is busy spin, and why should you use it?
What are loops in java? What are three types of loops?
Is it possible to specify multiple jndi names when deploying an ejb?
How many types of voids are there?
What is the difference between import java.util.date and java .util?
Difference between string, string builder, and string buffer?
Why are pointers not secure?
What is not object oriented programming?
What is data member in java?
Why string is not a wrapper class?
Can variables be used in java without initialization?