String

SN(序号) 方法描述
1 char charAt(int index) 返回指定索引处的 char 值。
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)
当且仅当字符串与指定的StringBuffer有相同顺序的字符时候返回真。
7 boolean endsWith(String suffix)
测试此字符串是否以指定的后缀结束。
8 boolean equals(Object anObject)
将此字符串与指定的对象比较。
9 boolean equalsIgnoreCase(String anotherString)
将此 String 与另一个 String 比较,不考虑大小写。
10 byte[] getBytes()
使用平台的默认字符集将此 String 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。
11 byte[] getBytes(String charsetName)
使用指定的字符集将此 String 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。
12 int hashCode() 返回此字符串的哈希码。
13 int indexOf(String str, int fromIndex)
返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。
14 int lastIndexOf(String str, int fromIndex)
返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索。
15 int length() 返回此字符串的长度。
16 boolean matches(String regex) 告知此字符串是否匹配给定的正则表达式。
17 String replace(char oldChar, char newChar) replace操作不会修改原始字符串!
返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 得到的。
18 String replaceAll(String regex, String replacement)
使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串。
19 String replaceFirst(String regex, String replacement)
使用给定的 replacement 替换此字符串匹配给定的正则表达式的第一个子字符串。
20 String[] split(String regex, int limit)
根据匹配给定的正则表达式来拆分此字符串,limit表示拆分份数
21 boolean startsWith(String prefix, int toffset)
测试此字符串从指定索引开始的子字符串是否以指定前缀开始。
22 CharSequence subSequence(int beginIndex, int endIndex)
返回一个新的字符序列,它是此序列的一个子序列。
23 String substring(int beginIndex, int endIndex)
返回一个新字符串,它是此字符串的一个子字符串。
24 char[] toCharArray() 将此字符串转换为一个新的字符数组。
25 String toUpperCase() String toLowerCase()
使用默认语言环境的规则将此 String 中的所有字符都转换为大/小写。
26 String toUpperCase(Locale locale) String toLowerCase(Locale locale)
使用给定 Locale 的规则将此 String 中的所有字符都转换为大/小写。
27 contains(CharSequence chars) 判断是否包含指定的字符系列。
28 isEmpty() 判断字符串是否为空。

StringBuilder,StringBuffer

String,StringBuilder,StringBuffer方法 - 图1
主要方法:

序号 方法描述
1 public StringBuffer append(String s)
将指定的字符串追加到此字符序列。
2 public StringBuffer reverse()
将此字符序列用其反转形式取代。
3 public delete(int start, int end)
移除此序列的子字符串中的字符。
4 public insert(int offset, int i)
将 int 参数的字符串表示形式插入此序列中。
5 insert(int offset, String str)
将 str 参数的字符串插入此序列中。
6 replace(int start, int end, String str)
使用给定 String 中的字符替换此序列的子字符串中的字符。

其他:

序号 方法描述
1 int capacity()
返回当前容量。
2 char charAt(int index)
返回此序列中指定索引处的 char 值。
3 void ensureCapacity(int minimumCapacity)
确保容量至少等于指定的最小值。
4 void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
将字符从此序列复制到目标字符数组 dst。
5 int indexOf(String str)
返回第一次出现的指定子字符串在该字符串中的索引。
6 int indexOf(String str, int fromIndex)
从指定的索引处开始,返回第一次出现的指定子字符串在该字符串中的索引。
7 int lastIndexOf(String str)
返回最右边出现的指定子字符串在此字符串中的索引。
8 int lastIndexOf(String str, int fromIndex)
返回 String 对象中子字符串最后出现的位置。
9 int length()
返回长度(字符数)。
10 void setCharAt(int index, char ch)
将给定索引处的字符设置为 ch。
11 void setLength(int newLength)
设置字符序列的长度。
12 CharSequence subSequence(int start, int end)
返回一个新的字符序列,该字符序列是此序列的子序列。
13 String substring(int start)
返回一个新的 String,它包含此字符序列当前所包含的字符子序列。
14 String substring(int start, int end)
返回一个新的 String,它包含此序列当前所包含的字符子序列。
15 String toString()
返回此序列中数据的字符串表示形式。

其他