Latest web development tutorials

Java getChars () method

Java String class Java String class


getChars () method to copy the characters from the string into the destination character array.

grammar

public void getChars(int srcBegin, int srcEnd, char[] dst,  int dstBegin)

parameter

  • srcBegin - index of the string to be copied the first character.

  • srcEnd - index of the last character in the string to be copied later.

  • dst - the destination array.

  • dstBegin - destination array starting offset.

return value

No return value, but it will throw an IndexOutOfBoundsException.

Examples

public class Test {
	public static void main(String args[]) {
		String Str1 = new String("www.w3big.com");
		char[] Str2 = new char[6];

		try {
			Str1.getChars(4, 10, Str2, 0);
			System.out.print("拷贝的字符串为:" );
			System.out.println(Str2 );
		} catch( Exception ex) {
			System.out.println("触发异常...");
		}
	}
}

The above program execution results:

拷贝的字符串为:w3big

Java String class Java String class