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 the specification of ?CODEBASE? in an applet?
How will you create the class for the following scenario? Employees under one employee?
Explain about assignment statement?
What primitive Java types? Howmany are they and what are their names?
I have one POJO class(Java bean class), it has two variables for that it has setters and getters. Now i have created two objects for that class and i have set the data for those variables through this two objects. Now question is i want check whether those two objects have same data or not, for this write a program? Thanks, Bose.
What is Collection interface?
Is it possible to make an array volatile?
Describe method overriding
What are disadvantages of java?
Can you explain the Java thread lifecycle?
What are the six ways to use this keyword?
What is the life cycle of Thread ?
12 Answers HCL, Varnar Softech,