adspace
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 parsing in java?
What is the difference between equals() and == in java?
explain different ways of using thread? : Java thread
What do you mean by an interface in java?
Differentiate between static and non-static methods in java.
Realized?
How to create a base64 decoder in java8?
Write a program to find the whether a number is an Armstrong number or not?
Write a program to print count of empty strings in java 8?
What is the difference between break and continue statements?
Is minecraft 1.15 out?
What is an object in java and how is it created?
What is a classloader in java?
Explain public static void main(string args[]) in java.
What are the differences between heap and stack memory in java?