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 is the difference between the paint() and repaint() methods?
What is data member in java?
Tell me about your ability to work under pressure
Are registers volatile?
Why is inheritance used in java?
Explain java heap space and garbage collection?
Explain methods specific to list interface?
What is a class component?
Is java written in c?
What is data object example?
How do you use compareto?
How we can execute any code even before main method?
What are the object and class classes used for?
What is stack explain?