Difference between String & StringBuffer

Answer Posted / nilesh bhil( mca) amravati

String is immutable.
It means that we cant change the content of String once created. If we try append a new string using + operator
then it creates new String object.
ex.
string s = new String("Java");
s = s + "bean" ;// this statement creates new object.
String class does not have method that append new String to old String in object.


where as StringBuffer class is mutable. It means that we can add new String to it using append() method.
ex.
StringBuffer sb = new StringBuffer("Java");
sb.append("Bean");

Is This Answer Correct ?    38 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain how to force the garbage collection in java.

516


Why singleton class is used in java?

553


What is command line argument

692


What kind of variables can a class consist?

575


Explain the available thread states in a high-level?

522






How do you remove all elements from an arraylist in java?

488


How will you initialize an Applet?

604


Define array. Tell me about 2-D array.

576


What does main method?

544


If try block is successfully executed, Then Is Finally block executed?

595


What is a variable in java?

518


What are data structures in java?

521


What does the exclamation mark mean in java?

580


What is flush buffer?

506


What is the advantage of functional interface in java 8?

504