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("sunnychen");
char[] Str2 = new char[6];
try {
Str1.getChars(0, 6, Str2, 0);
System.out.print("拷贝的字符串为:" );
System.out.println(Str2 );
} catch( Exception ex) {
System.out.println("触发异常...");
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/97676.html