1. 程式人生 > >String類下面的一些方法總結

String類下面的一些方法總結

這裡是由 String 類支援的方法列表:

1 char charAt(int index) 返回指定索引處的字元。 2 int compareTo(Object o) 將這個字串與另一個物件比較。 3 int compareTo(String anotherString) 比較兩個字串的字典順序。 4 int compareToIgnoreCase(String str) 比較兩個字串按字典順序,不區分大小寫的差異。 5 String concat(String str) 將指定的字串串連到這個字串的結尾。 6 boolean contentEquals(StringBuffer sb) 返回true當且僅當該字串代表相同的字元序列作為指定的StringBuffer。 7 static String copyValueOf(char[] data) 返回表示所指定的陣列中的字元序列的字串。 8 static String copyValueOf(char[] data, int offset, int count) 返回表示所指定的陣列中的字元序列的字串。 9 boolean endsWith(String suffix) 測試此字串是否以指定的字尾結束。 10 boolean equals(Object anObject) 比較此字串與指定的物件。 11 boolean equalsIgnoreCase(String anotherString) 比較這個字串到另一個字串,忽略大小寫的考慮。 12 byte getBytes() 將此String解碼使用平臺的預設字符集,並將結果儲存到一個新的位元組陣列中的位元組序列。 13 byte[] getBytes(String charsetName 將此String解碼使用指定的字符集的位元組序列,並將結果儲存到一個新的位元組陣列。 14 void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) 從這個字串複製字元到目標字元陣列。 15 int hashCode() 為這個字串返回一個雜湊程式碼。 16 int indexOf(int ch) 返回此字串指定字元第一次出現處的索引。 17 int indexOf(int ch, int fromIndex) 返回索引這個字串中指定字元第一次出現處,指定索引處開始搜尋。 18 int indexOf(String str) 返回此字串指定子字串的第一次出現處的索引。 19 int indexOf(String str,int fromIndex) 返回這個字串中指定子字串的第一次出現處的索引,從指定的索引處開始。 20 String intern() 返回字串物件的規範化表示。 21 int lastIndexOf(int ch) 返回此字串指定字元最後一次出現處的索引。 22 int lastIndexOf(int ch, int fromIndex) 返回此字串指定字元最後一次出現處的索引,從指定索引開始向後搜尋。 23 int lastIndexOf(String str) 返回此字串指定子字串的最右邊出現處的索引。 24 int lastIndexOf(String str, int fromIndex) 返回索引這個字串中指定子字串的最後出現處,從指定的索引開始處向後搜尋。 25 int length() 返回此字串的長度。 26 boolean matches(String regex) 判斷此字串是否與給定的正則表示式匹配。 27 boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) 測試兩個字串的區域等於。 28 boolean regionMatches(int toffset, String other, int ooffset, int len) 測試兩個字串的區域都是相等的。 29 String replace(char oldChar, char newChar) 返回從newChar更換oldChar所有出現在此字串中產生一個新的字串。 30 String replaceAll(String regex, String replacement 替換此字串中給定的正則表示式與給定替換相匹配的每個子字串。 31 String replaceFirst(String regex, String replacement) 替換此字串匹配給定的正則表示式給定替換第一個子字串。 32 String[] split(String regex) 分割圍繞給定的正則表示式匹配的這個字串。 33 String[] split(String regex, int limit) 分割圍繞給定的正則表示式匹配的這個字串。 34 boolean startsWith(String prefix) 測試此字串是否以指定的字首開頭。 35 boolean startsWith(String prefix, int toffset) 測試此字串是否以指定索引開始的指定字首開始。 36 CharSequence subSequence(int beginIndex, int endIndex) 返回一個新的字元序列,這個序列的子序列。 37 String substring(int beginIndex) 返回一個新的字串,它是此字串的一個子字串。 38 String substring(int beginIndex, int endIndex) 返回一個新的字串,它是此字串的一個子字串。 39 char[] toCharArray() 這個字串轉換為一個新的字元陣列。 40 String toLowerCase() 將所有在此字串中的字元使用預設語言環境的規則小寫。 41 String toLowerCase(Locale locale) 將所有在此字串中的字元使用給定Locale的規則小寫。 42 String toString() 這個物件(它已經是一個字串!)返回字串形式(這裡是自己本身)。 43 String toUpperCase() 使用預設語言環境的規則將此String中所有的字元轉換為大寫。 44 String toUpperCase(Locale locale) 使用給定Locale的規則將此String中所有的字元轉換為大寫。 45 String trim() 返回字串的一個副本,開頭和結尾的空格去除。 46 static String valueOf(primitive data type x) 返回傳遞的資料型別引數的字串表示形式。