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 a arraylist in java?
What is static and final keyword in java?
Can you sort a string in java?
What are the drawbacks for singleton class?
What is ternary operator in java?
What do you understand by private, protected and public?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread
Is this valid in java ? Can we instantiate interface in java?
Can we call virtual funciton in a constructor ?
Can size_t be negative?
What is application tier?
Explain throw keyword in java?
Program to Find the second largest element in an array.
How to make a read-only class in java?
What is the do while loop syntax?