Posted by: lrrp | January 24, 2015

String Vs StringBuffer Vs StringBuilder

What is difference between StringBuffer, String and StringBuilder in Java :

  1.  String is immutable while StringBuffer and StringBuilder is mutable object.
  2.  StringBuffer is synchronized while StringBuilder is not synchronized.
  3.  StringBuilder faster than StringBuffer due to synchronized implementaion of StringBuffer.
  4.  For String “+” operator is overrided and used for concatenation where append() method  is used for StringBuffer or StringBuilder concatenation .

When to use which?

Use String if you require immutability, use Stringbuffer in java if you need mutable + thread-safety and use StringBuilder in Java if you require mutable + without thread-safety.

Java Q & A Blog

View original post 91 more words


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: