Difference between String & StringBuffer

Answer Posted / niranjanravi

String objects are constants and immutable where as
StringBuffer objects are not.StringBuffer Class supports
growable and modifiable string where as String class
supports constant strings. Strings once created we cant
modify them. Any such attempt will lead to the creation of
new strings.Where as StingBuffer objects after creation
also can be able to delete oo append any characteres to
it.String values are resolved at run time where as
StringBuffer valuesc are resolved at compile time.So if you
know the exact size of the string to be appended it is
better to go for String objects.

Is This Answer Correct ?    194 Yes 19 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does this () mean in java?

521


What is hashing in java?

543


What is a double vs float?

515


Is it possible to compare various strings with the help of == operator? What are the risks involved?

592


Can we declare register variable as global?

488






How to display arraylist values in java?

465


How to split arraylist elements in java?

562


What does the ‘static’ keyword mean? Is it possible to override private or static method in java?

545


When should I use singleton?

500


What are thread priorities and importance of thread priorities in java?

602


Tell me a few examples of final classes defined in Java API?

544


Is there any limitation of using inheritance?

549


Variable of the boolean type is automatically initialized as?

563


How will you reverse a link list without using recursion?

565


Can static method access instance variables ?

568