Enter your E-mail Address below for Free E-mail Alerts right Into your Inbox: -

Wednesday

Difference between String and StringBuffer/StringBuilder in Java


Difference between String and StringBuffer/StringBuilder in Java

Each and every programmer in java are totally got confused about the basic difference between String,StringBuffer and StringBulder.

1.String


  • String is immutable i.e- the value assigned to a string can't be changed without assigning it
  • ex:- String s = "hai"; s.concat(" i am a boy"); System.out.println(s);
  • Output is "hai". not "hai i am a boy".

2.String Buffer

  • String Buffer is Synchronized.

  • It's thread safe.

  • mutable i.e- value can be changed.

3.String Builder

  • String Bulder is not Synchronized.

  • mutable i.e- value can be changed.

No comments:

Post a Comment