what is difference between String class, String Buffer & String Builder in java?

String class :

it is preferred when you are using your string variable not more than 10 times.. takes much more time in execution than other two…. immutable … loop of 10⁶ will take 20–30 mins

String Buffer class :

thread safe… comes with self locking… muttable…. loop of 10⁷ will take 800–900 milliseconds

String Builder :

asynchronized.. thread unsafe.. usually we do single thread coding.. fastest among all…. loop of 10⁷ will take 250–300 milliseconds

Conclusion : use StringBuilder , in multi-thread use StringBuffer

link there for the working code to play with