StringBuffer and StringBuilder in Java
Strings in Java are objects used to represent a sequence of characters. They can be either created using the String Literal or by using the NEW keyword. Strings are immutable in Java are represented in the UTF-16 format. When a new String is created, it looks for the String with the same value in the JVM string pool. If it finds the same value, then it returns the reference else it created a String object and places that object in the String.
Since Strings are immutable in Java, whenever String manipulations are performed, automatically a new String would be generated by discarding the older one. But, don’t you think, this is cumbersome when we have large applications?
Well, to avoid garbage in heap, Java came up with StringBuffer and StringBuilder
Click on the above video to understand the difference in details with the help of live example.