Online Java Compiler By
JavaTpoint.com
public class StringBuilderSetLengthExample2 { public static void main(String[] args) { StringBuilder sb = new StringBuilder("stringbuilder"); System.out.println("string: "+sb); System.out.println("length: "+sb.length()); //set new length of character sequence sb.setLength(20); System.out.println("set new length: "+sb.length()); System.out.println("new sequence: "+sb); } }
Output