Java 中的getChars()方法
目录
getChars()
方法将字符从字符串复制到目标字符数组。
语法
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
参数
- srcBegin — 字符串中要复制的第一个字符的索引。
- srcEnd — 字符串中要复制的最后一个字符之后的索引。
- dst — 目标数组。
- dstBegin — 目标数组中的起始偏移量。
返回值
没有返回值,但会抛出 IndexOutOfBoundsException
异常。
实例
public class Test { public static void main(String args[]) { String Str1 = new String("www.mybj123.com"); char[] Str2 = new char[7]; try { Str1.getChars(4, 11, Str2, 0); System.out.print("拷贝的字符串为:" ); System.out.println(Str2 ); } catch( Exception ex) { System.out.println("触发异常..."); } } }
以上程序执行结果为:
拷贝的字符串为:mybj123
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系maynote@foxmail.com处理
码云笔记 » Java 中的getChars()方法
码云笔记 » Java 中的getChars()方法
![](https://media.mybj123.com/wp-content/uploads/2024/02/1706962282-d2a91681b352c3a.png)