14 May String getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method in Java
The getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method in Java copies characters from this string into the destination character array.
Syntax
Let us see the syntax,
1 2 3 |
getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) |
Parameters
Let us see the parameters,
- srcBegin− index of the first character in the string to copy
- srcEnd− index after the last character in the string to copy
- dst− destination array
- dstBegin− start offset in the destination array
Example
The following is an example of getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin),
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import java.io.*; public class StudyopediaDemo { public static void main(String args[]) { String message1 = new String("Australia is a country!"); char[] message2 = new char[3]; try { message1.getChars(4, 7, message2, 0); System.out.println("Result: "); System.out.println(message2); } catch (Exception e) { System.out.println("Exception!"); } } } |
Output
The following is the output,
No Comments