top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between string and StringBuffer object in Java?

0 votes
619 views
What is the difference between string and StringBuffer object in Java?
posted Aug 9, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Hi, type String which represents string which is immutable and used for manipulation of character string only and this cannot be changed.It is also slow in compare to type StringBuffer which is faster in performance because whenever you perform a concatenation, it creates a new object internally.
You can compare the performance using operations like manipulation or concatenation, you will see the time taken by type String is much greater than type StringBuffer data.

answer Aug 22, 2017 by Shivam Kumar Pandey
Similar Questions
+4 votes

I was asked a question. If you had to build an XML structure as text, would you use StringBuffer or String? I thought String is more efficient that StringBuffer, but some of my friends say StringBuffer is more efficient than String.

I assume, that StringBuffer is a class, where as String is a base datatype and StringBuffer would have some easy (wrapper) methods for String. So, it is an add-on to string. Which should make StringBuffer heavier than String. Then how come using StringBuffer better than String?

...