Using StringBuffer to reverse a String
One thing to remember is that String objects are "immutable", meaning they can't be changed. So everytime we try to change a String, a new String object gets created.
This is a lot of overhead, and wastes memory.
This is where StringBuffer comes to the rescue. It is a "mutable" object, meaning it can be changed. It provides helper methods to modify the object.
I am sharing here a simple example to reverse a String using StringBuffer class.
Problem: Write a function that reverses a string. The input string is given as an array of characters char.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
You may assume all the characters consist of printable ascii characters.