What is the difference between String and StrigBuffer?

Questions by suri_veeru

Showing Answers 1 - 4 of 4 Answers

Amar

  • Mar 13th, 2006
 

String in Java are immutable, ihat is once a String is initialized with  certain value it cannot be changed but the reference to that String can be change to another String. While a String Buffer size can be always altered. The contentsof the StringBuffer can be changed by appending ned string or concatinating them with the later Strings.

Generally there will be asmall java code written in the interview where you will find that a String will be in a Loop and some constand String will be getting Added to the existing String. The wnswer will befinetly be the aaaaaaaaaaaaaaaaaaaaaaaa, if "a" is appended  soem nnuber of time, here Java will internally create a internal StringBuffer and do it for U.

  Was this answer useful?  Yes

nirmala

  • Mar 20th, 2006
 

string objects are constant & immutable

string Buffer objects are not  & immutable

  Was this answer useful?  Yes

Leninkumar

  • May 23rd, 2006
 

           String class is used to manipulate character strings that cannot be changed. Simply stated, objects of type String are read only and immutable. The StringBuffer class is used to represent characters that can be modified.

         The significant performance difference between these two classes is that StringBuffer is faster than String when performing simple concatenations. In String manipulation code, character strings are routinely concatenated. 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions