String Character Extraction getChars() method in Java?
Java String Handling
The String Character Extraction: getChars() method The getChars() method is used in java for copying String characters to an Array of chars. To extract more than one character at a time by using getChars() method.
/* Syntax of String Character Extraction: getChars() method*/
void getChars(int start, int end, char target[], int targetStart)
Here, start indicates the index of the beginning of the substring and end specifies an index that one past the end of the desired substring.
Program for getChars:
/* Example: */
class HB6
{
public static void main(String args[])
{
String s = "How are you? Dear student.";
int start=13;
int end=17;
char target[]= new char[end- start];
s.getChars(start,end,target,0);
System.out.println(target);
}
}
Sample Output