/**
 * Illustrates how to use StringBuilder for mutable character sequences.
 * 
 * @author Drue Coles
 */
public class StringBuilderDemo {

    public static void main(String[] args) {
        
        // Instantiate StringBuilder with a string.
        String letters = "abcdefghi";
        StringBuilder sb = new StringBuilder(letters);
        
        // Mutate sb: insert spaces.
        sb.insert(3, " ");
        sb.insert(7, " ");
        System.out.println(sb);
        
        // Mutate sb again: replace characters.
        sb.replace(4, 7, "###");
        System.out.println(sb);
        System.out.println();
       
        // Reverse a mutable string.
        sb = new StringBuilder(letters);
        System.out.println(sb);
        sb.reverse();
        System.out.println(sb);
    }
}