+1 vote
in JAVA by
Difference between String, StringBuffer and StringBuilder?

1 Answer

0 votes
by

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, 2021 in JAVA by Robindeniel
0 votes
asked Jul 9, 2023 in Snowflake by Robin
...