StringBuilder str = new StringBuilder("Hello World"); char[] ch = new char[5]; str.getChars(0, 5, ch, 0); System.out.println(ch);
StringBuilder str = new StringBuilder("Java is awesome"); char[] ch = new char[str.length()]; str.getChars(0, str.length(), ch, 0); System.out.println(ch);Output: "Java is awesome" In this example, we create a StringBuilder object 'str' with the string "Java is awesome". We then declare a char array 'ch' with a length equal to the length of the 'str' string. We pass the starting and ending index of 'str' (0, str.length()) and the destination array 'ch' with a starting index of 0. The output will be the entire 'str' string. The StringBuilder class is part of the java.lang package library.