getChars() Method In Java Example
Chapter:
String Handling
Last Updated:
10-06-2016 19:41:04 UTC
Program:
/* ............... START ............... */
public class JavaStringGetChars {
public static void main(String args[]) {
String Str1 = new String("Java Scan Program Collection");
char[] Str2 = new char[7];
try {
Str1.getChars(2, 9, Str2, 0);
System.out.println(Str2);
} catch (Exception ex) {
System.out.println("Exception...");
}
}
}
/* ............... END ............... */
Output
Notes:
-
getChars() method copies characters from string into the destination character array.
- Syntax : public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
- srcBegin -- index of the first character in the string to copy.
- srcEnd -- index after the last character in the string to copy.
- dst -- the destination array.
- dstBegin -- the start offset in the destination array.
Tags
getChars(), Java