27 string類中常用的方法列表
1. 獲取方法
int length() 獲取字符串的長度
char charAt(int index) 獲取特定位置的字符 (角標越界)
int indexOf(String str) 獲取特定字符的位置(overload)
int lastIndexOf(int ch) 獲取最後一個字符的位置
2. 判斷方法
boolean endsWith(String str) 是否以指定字符結束
boolean isEmpty() 是否長度為0 如:“” null V1.6
boolean contains(CharSequences) 是否包含指定序列 應用:搜索
boolean equals(Object anObject) 是否相等
boolean equalsIgnoreCase(String anotherString) 忽略大小寫是否相等
3. 轉換方法
String(char[] value) 將字符數組轉換為字符串
String(char[] value, int offset, int count)
Static String valueOf(char[] data)
static String valueOf(char[] data, int offset, int count)
char[] toCharArray() 將字符串轉換為字符數組
4. 其他方法
String replace(char oldChar, char newChar) 替換
String[] split(String regex) 切割
String substring(int beginIndex)
String substring(int beginIndex, int endIndex) 截取字串
String toUpperCase() 轉大寫
String toLowerCase() 轉小寫
String trim() 去除空格
27 string類中常用的方法列表