StringBuffer and StringBuilder
Both StringBuffer and StringBuilder are two important classes in Java which represents mutable String i.e. the String object, whose value can be changed. Since String is Immutable in Java, any change or operation on String object e.g. converting it to upper or lower case, adding character, removing a character, or getting a substring, all results in a new String object. Anyway, when StringBuffer was introduced it has its own problem e.g. it was synchronized, methods like append have synchronized and hence they were slower. Even if you use them by just one thread and don’t share with other threads, the cost of acquiring and releasing lock due to Synchronization is still significant. Since StringBuffer is mostly used as local mutable String variable making it synchronized wasn’t a great decision and Java designer realized their mistake and corrected it in Java 1.5 by introducing the StringBuilder class. As I have said that both StringBuffer and StringBuilder are a mutable alte...