StringBuilder sb = new StringBuilder("Hello World"); System.out.println("Before: " + sb.toString()); sb.setLength(5); System.out.println("After: " + sb.toString());
StringBuilder sb = new StringBuilder("Hello World"); System.out.println("Before: " + sb.toString()); sb.setLength(20); System.out.println("After: " + sb.toString());This code sets the length of the StringBuilder object to 20, which adds null characters to the end of the string. The StringBuilder class is part of the java.lang package library.