第三次学JAVA再学不好就吃翔(part55)--StringBuffer类的删除功能
生活随笔
收集整理的這篇文章主要介紹了
第三次学JAVA再学不好就吃翔(part55)--StringBuffer类的删除功能
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
學習筆記,僅供參考
文章目錄
- StringBuffer類
- StringBuffer類的刪除功能
- deleteCharAt方法
- delete方法
- 舉個例子
StringBuffer類
StringBuffer類的刪除功能
deleteCharAt方法
public StringBuffer deleteCharAt(int index)
Removes the char at the specified position in this sequence. This sequence is shortened by one char.
(不是翻譯)刪除指定位置的字符,并返回本身
-
參數
- index - Index of char to remove
-
返回
- This object.
delete方法
public StringBuffer delete(int start,int end)
Removes the characters in a substring of this sequence. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such character exists. If start is equal to end, no changes are made.
-
參數
- start - The beginning index, inclusive.
- end - The ending index, exclusive.
-
返回
- This object.
舉個例子
package com.guiyang.restudy3;public class D3StringBuffer {public static void main(String[] args) {StringBuffer sb = new StringBuffer(); //sb.deleteCharAt(5); //當緩沖區中這個索引上沒有元素的時候就會報StringIndexOutOfBoundsExceptionsb.append("HuangHei");sb.deleteCharAt(6); //根據索引刪除掉索引位置上對應的字符System.out.println(sb);sb.delete(0, 2); //刪除的時候是包含頭,不包含尾System.out.println(sb);sb.delete(0, sb.length()); //清空緩沖區System.out.println(sb);}}
輸出:
HuangHi angHi創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
以上是生活随笔為你收集整理的第三次学JAVA再学不好就吃翔(part55)--StringBuffer类的删除功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tcl王牌电视机如何连接电脑
- 下一篇: 第三次学JAVA再学不好就吃翔(part