in JAVA by
Difference between String, StringBuffer and StringBuilder?

1 Answer

0 votes

The string is immutable and final in Java, so whenever we do String manipulation, it creates a new String. String manipulations are resource consuming, so java provides two utility classes for String manipulations – StringBuffer and StringBuilder.

StringBuffer and StringBuilder are mutable classes. StringBuffer operations are thread-safe and synchronized where StringBuilder operations are not thread-safe. So in a multi-threaded environment, we should use StringBuffer but in the single-threaded environment, we should use StringBuilder.

StringBuilder performance is fast than StringBuffer because of no overhead of synchronization.

Related questions

0 votes
asked May 3 in JAVA by Robindeniel
+1 vote
asked Jan 20, 2020 in C Sharp by AdilsonLima