StringBuilder str = new StringBuilder("Hello World"); String subStr = str.substring(6,11); System.out.println(subStr);
StringBuilder str = new StringBuilder("Java Programming"); String subStr = "is fun"; str.append(subStr, 3, 6); System.out.println(str);Output: Java Programming fun In this example, a new StringBuilder object is created with the value "Java Programming". The substring "is fun" is stored in a string variable. The append() method is called on the StringBuilder object to add the substring to it, starting from the 3rd index (inclusive) to the 6th index (exclusive). The resulting modified string is printed. The package library used in these examples is java.io.