9.1 字符串基本操作
length
chatAt
indexOf( char ch, int start) ---查找下標
lastIndexOf( char ch,int start)
9.2 字符串比較
equals equalsIgnoreCase
compareTo compareToIgnoreCase
比較串的部分
regionMatches( boolean ignoreCase, int start, String other, int ostart, int count)
檢查字符串的開頭和結尾
startsWith( String prefix, int start)
endsWith( String suffix)
9.3 工具方法
hashCode
intern
返回一個與它的字符串內容相同的Stirng對象,把比較對象引用等同於比較對象內容
9.4 創建相關的字符串
substring
public String replace(char oldChar, char newChar)
public String trim() ---刪去開頭和結尾的空白符
toLowerCase toUpperCase
concat
9.6 字符串和 char數組
從char數組創建String
public String( char[ ] chars, int start, int count)
public String( char[ ] chars) 等價於String( chars , 0, chars.length)
從String創建char數組
public char[ ] toCharArray()
public getChars(int srcBegin, int srcEnd, char[ ] dst, int dstBegin)
9.8 StringBuffer類
1 修改緩衝區
void setCharAt( int index, char ch) --改變特定位置上的字符
void setLength( int newLength )--截斷或擴展緩衝區裏的字符串
添加重載形式之一
public StringBuffer append(char[ ] str, int offset, int len) --將任意數據類型轉換爲String,在將結果添加到尾部
插入重載形式之一
public StringBuffer insert(int pos ,char[ ] chars,int start ,int count)--將任意數據類型轉換爲String,再將結果插入到指定的位置
reverse -- 反轉
delete --刪除緩衝區的一部分
deleteCharAt --刪除單個字符
2 取出數據
toString
substring
形成一個字符數組
public void getChars(int srcBegin,int srcEnd, char[ ] dst, int dstBegin)