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


Please Help Members By Posting Answers For Below Questions

What is parsing in java?

1041


What is the difference between equals() and == in java?

1039


explain different ways of using thread? : Java thread

1081


What do you mean by an interface in java?

1102


Differentiate between static and non-static methods in java.

1127


Realized?

2261


How to create a base64 decoder in java8?

1138


Write a program to find the whether a number is an Armstrong number or not?

1098


Write a program to print count of empty strings in java 8?

1086


What is the difference between break and continue statements?

1127


Is minecraft 1.15 out?

1045


What is an object in java and how is it created?

1140


What is a classloader in java?

1088


Explain public static void main(string args[]) in java.

1076


What are the differences between heap and stack memory in java?

1139