Java String.getChars()方法
Java String.getChars()方法用法实例教程,从这个字符串中的字符复制到目标字符数组
width="728" height="90" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_0" name="aswift_0" style="box-sizing: border-box; left: 0px; position: absolute; top: 0px;">
id="cproIframe_u1064372_1" width="728" height="90" src="http://pos.baidu.com/acom?adn=3&at=38&aurl=&cad=1&ccd=24&cec=UTF-8&cfv=16&ch=0&col=zh-CN&conOP=0&cpa=1&dai=1&dis=0<r=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D7GHAUgeoB8Z9BYTR-UO2iJmkQWcwT6VULEB6R1uvxBZFEECWGtWBU4ZOMzfQJg3j0fj4ja5gS7A6ZuNd2J-TIa%26wd%3D%26eqid%3Db441c7b30003582100000005565270bb<u=http%3A%2F%2Fwww.yiibai.com%2Fjavalang%2Fstring_getchars.html&lunum=6&n=90029059_cpr&pcs=1194x548&pis=10000x10000&ps=304x354&psr=1366x768&pss=1194x1462&qn=d3d79e902f912465&rad=&rsi0=728&rsi1=90&rsi5=4&rss0=%23FFFFFF&rss1=%23FFFFFF&rss2=%230000FF&rss3=%23444444&rss4=%23008000&rss5=&rss6=%23e10900&rss7=&scale=&skin=&td_id=1064372&tn=text_default_728_90&tpr=1448243367382&ts=1&version=2.0&xuanting=0&dtm=BAIDU_DUP2_SETJSONADSLOT&dc=2&di=u1064372&ti=Java%20String.getChars()%E6%96%B9%E6%B3%95&tt=1448243367312.71.190.194" align="center,center" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="box-sizing: border-box;">
描述
java.lang.String.getChars() 方法从这个字符串中的字符复制到目标字符数组
要复制的第一个字符在索引srcBegin处,被复制的最后一个字符是在的索引srcEnd1即要复制的字符总数是srcEnd srcBegin处。
字符被复制到子数组的夏令时开始在指数dstBegin和结束于索引:dstbegin + (srcEnd-srcBegin) - 1
声明
以下是声明java.lang.String.getChars()方法
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
参数
-
srcBegin -- This is the index of the first character in the string to copy.
-
srcEnd -- This is the index after the last character in the string to copy.
-
dst -- This is the destination array.
-
dstBegin -- This is the start offset in the destination array.
返回值
此方法不返回任何值
异常
-
IndexOutOfBoundsException -- 如果以下是true,它抛出这个异常:
srcBegin is negative srcBegin is greater than srcEnd srcEnd is greater than the length of this string dstBegin is negative dstBegin+(srcEnd-srcBegin) is larger than dst.length
实例
下面的例子显示使用的java.lang.String.getChars()方法
package com.yiibai; import java.lang.*; public class StringDemo { public static void main(String[] args) { String str = "Website:www.yiibai.com"; System.out.println(str); // character array char[] chararr = new char[30]; /* copies characters from starting and ending index into the destination character array */ str.getChars(12, 26, chararr, 0); // print the character array System.out.print("Value of character array : "); System.out.println(chararr); } }
让我们来编译和运行上面的程序,这将产生以下结果:
Website:www.yiibai.com Value of character array : yiibai