語法
以下是此方法的語法
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
參數
srcBegin
- 要復制的字符串中第一個字符的索引。srcEnd
- 要復制的字符串中最后一個字符后面的索引。dst
- 目標數組。dstBegin
- 目標數組中的起始偏移量。
返回值
- 它不返回任何值,但可能會拋出
IndexOutOfBoundsException
。
1 import java.io.*; 2 3 public class Test { 4 5 public static void main(String args[]) { 6 String Str1 = new String("Welcome to Yiibai.com"); 7 char[] Str2 = new char[7]; 8 try { 9 Str1.getChars(8, 15, Str2, 0); 10 System.out.print("Copied Value = "); 11 System.out.println(Str2); 12 } catch (Exception ex) { 13 System.out.println("Raised exception..."); 14 } 15 } 16 }
執行上面示例代碼,得到以下結果:
Copied Value = to Yiib
作者: celin_Angel Java技術QQ群:227270512 / Linux QQ群:479429477
原文出自【易百教程】,商業轉載請聯系作者獲得授權,非商業轉載請保留原文鏈接:https://www.yiibai.com/java/java_string_getchars.html