what is the main difference between string and stringbuffer?
can you explain it with program?
Answers were Sorted based on User's Feedback
Answer / divya
String class is used to manipulate character strings that
cannot be changed.Simply stated,objects of the String are
read only and immutable.
StringBuffer class is used to represent characters that can
be modified.
Ex:Sting str=new String("core");
str +="Java";
StringBuffer str=new StringBuffer("core");
str.append("Java");
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / 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 |
what is class.forname() and how it will be useful ?
String class is defined under which package in java?
How many types of assembly languages are there?
finalize() method?
How many types of keywords are there?
Difference between nested and inner classes ?
Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?
Can a class have an interface?
Find the value of a specified element of the array arr[i] where 0 <= i <= n-1
What are the disadvantages of using inner classes?
What is the default execution method in java?
Can a constructor be private and how are this() and super() method used with constructor?
0 Answers Flextronics, Hexaware,