We already know that the constructors of the String class, String(char a[]) and String(char a[], int offset, int length), create string objects using all characters and part of the characters in array a respectively. The String class also provides a method for storing strings in an array: public void getChars(int start, int end, char c[], int offset).
The string calls the getChars() method to copy part of the characters in the current string to the array specified by parameter c, copy the characters from position start to end-1 in the string to array c, and copy the characters from array c These characters are stored starting at offset.
Note : It must be ensured that array c can accommodate the characters to be copied.
In addition, there is a method that simply stores all the characters in a string in a character array: public char[] toCharArray().
The string object calls this method to return a character array. The length of the array is equal to the length of the string. The character in the i-th unit is exactly the i-th character in the current string.