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 are the steps in the jdbc connection?
What is a singleton in genetics?
Explain inheritance in java?
Write a program to find maximum and minimum number in array?
Can you use abstract and final both with a method?
What is another word for methodology?
What is operator overloading. Is it is supported in java?
What is the basic of java?
What is methods in java?
what is server side caching?
Is java a prime method?
Can abstract class have private constructor?
How is it possible for two string objects with identical values not to be equal under the == operator?
Can java hashmap have duplicate keys?
What is the protected method modifier?