|
No. |
方法名稱 |
功能 |
|
字元與字串 |
|
01 |
public String(char[] value) |
將字元數組中所有內容變為字串 |
|
02 |
public String(char[] value,int offset,int count) |
將字元數組中部分內容變為字串 |
|
03 |
public char charAt(int index) |
取得指定索引位置的字元,索引從0開始 |
|
04 |
public char[] toCharArray() |
將字串變為字元數組返回 |
|
位元組與字串 |
|
01 |
public String(byte[] bytes) |
將位元組數組中所有內容變為字串 |
|
02 |
public String(byte[] bytes,int offset,int length) |
將位元組數組中部分內容變為字串 |
|
03 |
public byte[] getBytes() |
將字串以位元組數組的形式返回 |
|
04 |
public byte[] getBytes(String charsetName) throws UnsupportedEncodingExcepetion |
編碼轉換處理 |
|
字串比較 |
|
01 |
public boolean equals(String anObject) |
區分大小寫比較 |
|
02 |
public boolean equalsIgnoreCase(String anotherString) |
不區分大小寫比較 |
|
03 |
public int compareTo(String anotherString) |
比較兩個字串的大小關係 |
|
字串尋找 |
|
01 |
public boolean contains(String s) |
判斷一個子字串是否存在 |
|
02 |
public int indexOf(String str) |
從頭開始尋找指定字元的位置,查到了返回位置的開始索引,查不到返回-1 |
|
03 |
public int indexOf(String str,int fromIndex) |
從指定位置尋找子字元的位置 |
|
04 |
public int lastIndex(String str) |
從後往前尋找子字元的位置 |
|
05 |
public int lastIndex(String str,int fromIndex) |
從指定位置由後往前尋找子字元的位置 |
|
06 |
public boolean startsWith(String prefix) |
從頭開始判斷是否以指定的字串開頭 |
|
07 |
public boolean startsWith(String prefix,int toffset) |
從指定位置開始判斷是否以指定的字串開頭 |
|
08 |
public boolean endsWith(String suffix) |
判斷是否以指定的字串結尾 |
|
字串替換 |
|
01 |
public String replaceAll(String regex,String replacement) |
替換所有內容 |
|
02 |
public String replaceFirst(String regex,String replacement) |
替換首個內容 |
|
字串拆分 |
|
01 |
public String[] split(String regex) |
將字串全部拆分 |
|
02 |
public String[] split(String regex,int limit) |
將字串部分拆分,該數組長度就是limit |
|
字串截取 |
|
01 |
public String substring(int beginIndex) |
從指定索引截取到結尾 |
|
02 |
public String substring(int beginIndex,int endIndex) |
截取部分內容 |
|
其他動作 |
|
01 |
public String trim() |
去掉字串中的左右空格,保留中間空格 |
|
02 |
public String toUpperCase() |
字串轉大寫 |
|
03 |
public String toLowerCase() |
字串轉小寫 |
|
04 |
public String interm() |
字串入對象池 |
|
05 |
public String concat(String str) |
字串串連,等同於”+” |
|
06 |
public int length() |
取得字串長度 |
|
07 |
public boolean inEmpty() |
判斷是否為空白(不是null,而是長度為空白) |