String API
API
Question1: String底层是什么?
Ans:属于java.lang
charAt(int index)
Returns the car value at the specified index
compareTo(String anotherString)
Compare two strings lexicographically.
compareToIgnoreCase
Compares two strings lexicographically, ignoring case differences
concat(String str)
Concatenates the specified string to the end of this string.
equals(Object anObject)
Compares this string to the specified object.
equalsIgnoreCase(String anotherString)
Compares this String to another String, ignoring case considerations
indexOf(int ch)
Returns the index within this string of the first occurrence of the specified character
indexOf(String str)
Returns the index within this string of the first occurrence of the speecified substring
length()
Returns the length of this string
repeat(int count)
Returns a string whose value is the concatenation of this string repeated count times.
replace(char oldChar, char newChar)
Returns a string resulting from replacing all occurrences of oldChar in this string with newChar.
replaceAll(String regex, String replacement)
Replace each substring of this string that matches the given regular expression with the given replacement.
split(String regex)
Splits this string around matches of the given regular expression.
split(String regex, int limit)
Splits this string around matches of the given regular expression.
substring(int beginIndex)
Returns a string that is a substring of this string.
substring(int beginIndex, int endIndex)
Returns a string that is a substring of this string.
toCharArray()
Converts this string to a new character array.
你可以最后再变回去String newStr = new String((array), 这里array是一个char[] array(为了修改我必须如此,StringBuildler使用的概率小
toLowerCase()
Convert all of the characters in this String to lowercase using the rules of the default locale.
toString()
This object(which is already a string!)
toUppderCase()
Coverts all of the characters in this String to upper case using the rules of the default locale.
trim()
Return a string whose value is this string, with all leading and trailing space removed, where space is defined as any character whose codepoint is less than or equal to 'U+0020' (the space character).
repeat()
Returns a string whose value is the concatenation of this string repeated count times
String[] split(String regex)
String[] split(String regex, int limit)
startsWith(String prefix)
Check whether a string starts with the specified characters.
endsWith(String suffix)
Check whether a string ends with the specified characters.
intern()
API 1: charAt() method
API 2: compareTo() method
lexicographically
API 3: comparetToIgnoreCase() method
API 4: String concat(String)作用等同于String做加法
API 5: boolean equals(Object anObject)
API 6: boolean equalsIgnoreCase(String anotherString)
API 7: int indexOf(int ch)
API 8: int indexOf(String str)
API 9: int length()
API 10: String replace(char oldChar, char newChar)
API 11: deleteCharAt(int index)
API 12: string replaceAll(String regex, String replacement)
API 13: String substring(int beginIndex):[index....]
API 14: String substring(int beginIdnex, int endIndex) [beginIndex, endIndex)
API 15: char[] toCharArray()
API 16: String toLowerCase()
API 17: String toUpperCase()
API 18: String toString()
API 19: String trim()
API 20: repeat(int count)
API 21: String[] split(String regex)
API 22: String[] split(String regex, int limit)
API 23 startsWith(String prefix)
API 24 endsWith(String suffix)
API 25 intern()
Last updated