日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java StringBuilder getChars()方法与示例

發布時間:2023/12/1 java 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java StringBuilder getChars()方法与示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

StringBuilder類的getChars()方法 (StringBuilder Class getChars() method)

  • getChars() method is available in java.lang package.

    getChars()方法在java.lang包中可用。

  • getChars() method is used to copy all the characters from the given arguments (int src_st, int src_end) into another destination array of char type like char[] dest.

    getChars()方法用于將給定參數(int src_st,int src_end)中的所有字符復制到另一個char類型的目標數組中,例如char [] dest。

  • In this method copy first character starts at index src_st and copying the last character ends at index src_end so all the copied characters will be placed in an array char[] dest and this array index starts at dest_st and ends at dest_beg+(src_end-src_beg)-1.

    在此方法中,復制第一個字符開始于索引src_st ,復制最后一個字符結束于索引src_end,因此所有復制的字符都將放置在char [] dest數組中,并且此數組索引開始于dest_stg并結束于dest_beg +(src_end-sr??c_beg) -1 。

  • getChars() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    getChars()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • This method may throw an exception at the time of copying and placing copied characters.

    在復制和放置復制的字符時,此方法可能會引發異常。

    • IndexOutOfBoundsException – This exception may throw when src_st < 0 or dest_st < 0 or src_st > src_end or src_end > length().
    • IndexOutOfBoundsException-當src_st <0或dest_st <0或src_st> src_end或src_end> length()時,可能引發此異常。
    • NullPointerException – This exception may throw when char[] array is null exists.NullPointerException-如果char []數組為null,則可能引發此異常。

Syntax:

句法:

public void getChars(int src_st, int src_end, char[] dest, int dest_st);

Parameter(s):

參數:

  • int src_st – represents the index to start copying.

    int src_st –表示要開始復制的索引。

  • int src_end – represents the index to end copying.

    int src_end –表示結束復制的索引。

  • int char[] dest – represents the array for copied elements.

    int char [] dest –表示復制元素的數組。

  • int dest_beg – represents the index of starting position of char[] dest.

    int dest_beg –表示char [] dest的起始位置的索引。

Return value:

返回值:

The return type of this method is void, it returns nothing.

此方法的返回類型為void ,不返回任何內容。

Example:

例:

// Java program to demonstrate the example // of getChars(int src_st, int src_end, char[] dest, int dest_st) // method of StringBuilder public class GetChars {public static void main(String[] args) {int src_st = 0;int src_end = 4;int dest_st = 0;// Creating an StringBuilder objectStringBuilder st_b = new StringBuilder("Java World");// Display st_bSystem.out.println("st_b = " + st_b);char[] dest = new char[] {'a','b','c','d','e','f','g','h','i','j'};// By using getChars() method is to copy the chars from the// given src_st to src_end of st_b and placed into dest[] // and position of placing the copied chars starts at dest_stst_b.getChars(src_st, src_end, dest, dest_st);// Display destination arrayfor (char val: dest)System.out.print("" + val);} }

Output

輸出量

st_b = Java World Javaefghij

翻譯自: https://www.includehelp.com/java/stringbuilder-getchars-method-with-example.aspx

總結

以上是生活随笔為你收集整理的Java StringBuilder getChars()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。