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 object
StringBuilder st_b = new StringBuilder("Java World");
// Display st_b
System.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_st
st_b.getChars(src_st, src_end, dest, dest_st);
// Display destination array
for (char val: dest)
System.out.print("" + val);
}
}

Output

輸出量

st_b = Java World
Javaefghij

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379161.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379161.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379161.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Python---利用蒙特.卡羅方法計算圓周率近似值

利用蒙特.卡羅方法計算圓周率近似值 什么是蒙特.卡羅方法&#xff1f; 答&#xff1a;蒙特卡羅方法是一種計算方法。原理是通過大量隨機樣本&#xff0c;去了解一個系統&#xff0c;進而得到所要計算的值。 正方形內部有一個相切的圓&#xff0c;它們的面積之比是π/4。 這里假…

不具有繼承關系的Delegate如何進行類型轉換?

- 引自:Artech 我們知道對于兩個不具有繼承關系的兩個類型&#xff0c;如果沒有為它們定義轉換器&#xff0c;兩這之間的類型轉換是不允許的&#xff0c;Delegate也是如此。但是有時候我們卻希望“兼容”的兩種Delegate類型能夠進行轉換&#xff0c;比較典型的就是表示事件的De…

Java屬性loadFromXML()方法與示例

屬性類loadFromXML()方法 (Properties Class loadFromXML() method) loadFromXML() method is available in java.util package. loadFromXML()方法在java.util包中可用。 loadFromXML() method is used to load all the properties denoted by the XML file on the given inpu…

FLV封裝格式的分析

FLV封裝格式的分析&#xff0c;各種詳細的參數比較多沒有詳細解釋&#xff0c;這是總體的格式分布。詳細的參數說明可以參照文檔。 以flv格式內封裝的音頻流是aac、視頻流是h264分析&#xff1a; flv文件tag部分截圖&#xff1a;可以看到音頻TAG、視頻TAG是交錯存儲的

《計算機基礎復習》===數據庫技術基礎

數據庫系統三級結構&#xff1a; 數據庫系統一般劃分為三個抽象級&#xff1a;用戶級、概念級、物理級。 1&#xff09;用戶級數據庫&#xff1a;對應于外模式。它是用戶看到和使用的數據庫&#xff0c;又稱用戶視圖&#xff1b;用戶級數據庫主要由外部記錄組成&#xff0c;不同…

bs架構 erp 進銷存_從依賴經驗到用柔性ERP,企業少走了多少彎路?

企業在面對緊急訂單時&#xff0c;傳統企業將面臨兩難問題&#xff1a;如不接受緊急訂單,可能會導致潛在的顧客丟失,損失市場占有率;接受緊急訂單,可能會給企業帶來很多管理上的問題,如材料采購、庫存管理等。而企業通過信息化手段提升生產計劃與控制的柔性&#xff0c;則可從容…

Python---統計《三國演義》中出現次數較高的人物

統計《三國演義》中出現次數較高的人物。 import jieba excludes{"先主","將軍","卻說","荊州","二人","不可","不能","如此","忽然","下馬","喊聲","馬…

Java RandomAccessFile close()方法與示例

RandomAccessFile類close()方法 (RandomAccessFile Class close() method) close() method is available in java.io package. close()方法在java.io包中可用。 close() method is used to close this RandomAccessFile stream and free all other system resources linked wit…

云端: 小軟件大平臺,綠色又安全 V0.9 Beta3(090722)

云端 是一個小軟件&#xff0c;但又是一個大平臺。安裝云端之后&#xff0c;再使用其他軟件不再需要安裝——一點、下載、直接使用&#xff1b;并且&#xff0c;通過虛擬化的運行環境&#xff0c;能夠保持系統長久的干凈、綠色&#xff0c;并保持軟件與系統的安全隔離——此方面…

MGraph圖(代碼、分析、匯編)

目錄:代碼&#xff1a;分析&#xff1a;匯編&#xff1a;MGrapth圖表示有鄰接矩陣的方式構成的圖結構。鄰接矩陣用兩個數組保存數據&#xff0c;一個一維數組存儲圖中的頂點信息&#xff0c;一個二維數組存儲圖中邊或弧的信息。無向圖中的二維數組是個對稱矩陣 1.0表示無邊&…

java: 程序包lombok不存在_Java開發神器:Lombok 學習指南

點擊上方“Java知音”&#xff0c;選擇“置頂公眾號”技術文章第一時間送達&#xff01;作者&#xff1a;semlinkerwww.segmentfault.com/a/1190000020864572一、Lombok 簡介Lombok 是一款 Java 開發插件&#xff0c;使得 Java 開發者可以通過其定義的一些注解來消除業務工程中…

Python---編程檢查并判斷密碼字符串的安全強度

編程檢查并判斷密碼字符串的安全強度 passwordinput("請輸入你的密碼&#xff1a;") plist(password) x0 for i in p:if i " ":x1 if x1:print("密碼格式不對")#密碼中不能包含空格 elif password.isdigit()True or password.isalpha()True:#全…

CFUpdate上傳控件的使用

一同事找的這個控件&#xff0c;覺得挺不錯的&#xff0c;到官方(http://www.access2008.cn/)下載源碼后稍加修改 html頁面代碼&#xff1a; <html xmlns"http://www.w3.org/1999/xhtml" xml:lang"zh_cn" lang"zh_cn"> <head> <m…

observable_Java Observable addObserver()方法與示例

observable可觀察的類addObserver()方法 (Observable Class addObserver() method) addObserver() method is available in java.util package. addObserver()方法在java.util包中可用。 addObserver() method is used to insert the given observer (obs) to the bundles of o…

AAC ADTS格式分析

AAC ADTS格式分析&#xff1a; 沒有詳細的參數說明&#xff0c;只有格式分析。可以查詢文檔查看詳細參數說明。 ADTS的全稱是Audio Data Transport Stream。是AAC音頻的傳輸流格 式。AAC音頻格式在MPEG-2&#xff08;ISO-13318-7 2003&#xff09;中有定義。AAC后來 又被采用到…

新知道的幾個東西

nginx&#xff08;發音同engine x&#xff09;是一款由俄羅斯程序設計師Igor Sysoev所開發輕量級的網頁服務器、反向代理服務器以及電子郵件&#xff08;IMAP/POP3&#xff09;代理服務器。起初是供俄國大型的入口網站及搜尋引擎Rambler&#xff08;俄文&#xff1a;Рамбл…

臺達plc控制伺服電機編程實例_PLC控制伺服電機:控制脈沖的相關計算

伺服電機PLC通過脈沖的方式控制伺服電機時&#xff0c;其輸出脈沖與伺服電機的配置應具有一定的對應關系。如&#xff0c;PLC輸出多少個脈沖電機旋轉一圈&#xff1f;電機旋轉一圈移動的距離(或角度)是多少&#xff1f;這里我們以某伺服電機為例進行舉例說明&#xff1a;完成對…

linux rm命令詳解

用戶可以用rm命令刪除不需要的文件。該命令的功能為刪除一個目錄中的一個或多個文件或目錄&#xff0c;它也可以將某個目錄及其下的所有文件及子目錄均刪除。對于鏈接文件&#xff0c;只是斷開了鏈接&#xff0c;原文件保持不變。 rm命令的一般形式為&#xff1a;rm [選項] 文件…

rotateright_Java Long類rotateRight()方法的示例

rotateright長類rotateRight()方法 (Long class rotateRight() method) rotateRight() method is available in java.lang package. rotationRight()方法在java.lang包中可用。 rotateRight() method is used to returns the value generated by rotating the binary 2’s comp…

實驗四 Windows程序設計

1&#xff0c;創建Windows窗體應用程序&#xff0c;實現用戶登錄功能&#xff0c;當輸入正確與錯誤時均給出相應的提示信息&#xff0c;規定用戶輸入錯誤次數不能超過3次。&#xff08;源代碼運行界面&#xff09; 這里的口令有個小常識&#xff0c;就是顯示*&#xff0c;在口令…