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 instanceof keyword?
What are the loops in java?
Why main function is static?
What is an object’s lock and which object’s have locks?
What are inner classes or non static nested classes in java?
What are the different types of inheritance in java?
What is a stringbuilder?
What is set in java?
What is double parsedouble in java?
What are the steps in the jdbc connection?
What will happen if there is a default method conflict as mentioned above and we have specified the same signature method in the base class instead of overriding in the existing class ?
Why do we declare a class static?
What is the difference between synchronized and synchronized block?
Difference between abstract and concrete class ?
How do you make an arraylist empty in java?