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
Write a program to reverse array in place?
What’s the difference between unit, integration and functional testing?
Does java support function overloading, pointers, structures, unions or linked lists?
Can a java program have 2 main methods?
How java uses the string and stringbuffer classes?
Explain about public and private access specifiers?
Compare overloading and overriding?
Is an integer an object?
How do you stop a thread in java?
What is java instanceof operator?
What is the advantage of OOP in java?
How do you convert boolean to boolean?
What is sortedmap interface?
Do you know why doesn't the java library use a randomized version of quicksort?
What is difference between overloading and overriding in java?