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 is a protected method?

591


Find the value of a specified element of the array arr[i] where 0 <= i <= n-1

537


What methods are used to get and set the text label displayed by a button object?

550


What is string :: npos?

577


Can an interface have a constructor?

511






What is connection class in java?

508


I want to persist data of objects for later use. What is the best approach to do so?

589


What is the purpose of object oriented programming?

532


What is multi-catch block in java?

613


What is boolean logic?

559


How do you write a scanner class in java?

560


Does treeset allow null in java?

506


What are the main concepts of oops in java?

592


what are three ways in which a thread can enter the waiting state? : Java thread

570


What is considered an anti pattern?

523