concept StringBuilder object in category java

appears as: StringBuilder object, StringBuilder objects
Java SE 11 Programmer I Certification Guide

This is an excerpt from Manning's book Java SE 11 Programmer I Certification Guide.

Apart from using the method substring, you can also use the method subSequence to retrieve a subsequence of a StringBuilder object. This method returns objects of type CharSequence:

class SubSequenceStringBuilder {
    public static void main(String args[]) {
        StringBuilder sb1 = new StringBuilder("0123456");
        System.out.println(sb1.subSequence(2, 4));    #A
        System.out.println(sb1);                      #B
    }
}

The method subsequence doesn’t modify the existing value of a StringBuilder object.

Unlike the String objects, StringBuilder objects are mutable. The append and delete methods defined in this class change its value. ejg.delete(3, 6) modifies the existing value of the StringBuilder to 12S5. It then appends the same value to itself when calling ejg.append(), resulting in the value 12S512S5.