Java StringBuilder getChars() Method Example

Java StringBuilder getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method - Characters are copied from this sequence into the destination character array dst.

Java StringBuilder getChars() Method Example

Example to copy characters from this sequence into the destination character array dst.
public class GetCharsExample {
    public static void main(String[] args) {
        StringBuilder builder = new StringBuilder("javaguides");
        char[] dst = new char[builder.length()];
        builder.getChars(0, builder.length(), dst, 0);
  
        for (char c : dst) {
             System.out.println(c);
        }
    }
}
Output:
j
a
v
a
g
u
i
d
e
s

Reference


Comments