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 happens when a class is made static like if a field or member is made static it becomes class variable and is shared by all the object of the class?
Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects are same? Thanks in advance.
What do you mean by multithreaded program?
What is the similarity between dynamic binding and linking?
What is flush () in java?
I am a fresher and know core java, c languge, html, css etc if I am illegible for any job then send it on my email tatranakshay276@gmail.com
If a class is declared without any access modifiers, where can the class be accessed?
What is a numeric format?
What do you mean by local variable and instance variable?
What are the disadvantages of object oriented programming?
What exactly is methodology?
How many types of interfaces are there?