String 常用方法备忘

来源:互联网 发布:windows字体打包下载 编辑:程序博客网 时间:2024/05/18 01:43

int compareTo(String anotherString) 
          按字典顺序比较两个字符串。 
int compareToIgnoreCase(String str) 
          按字典顺序比较两个字符串,不考虑大小写。 
String concat(String str) 
          将指定字符串连接到此字符串的结尾。 
boolean contains(CharSequence s) 
          当且仅当此字符串包含指定的 char 值序列时,返回 true。 
boolean endsWith(String suffix) 
          测试此字符串是否以指定的后缀结束。 
boolean equalsIgnoreCase(String anotherString) 
          将此 String 与另一个 String 比较,不考虑大小写。 
int indexOf(String str) 
          返回指定子字符串在此字符串中第一次出现处的索引。 
int indexOf(String str, int fromIndex) 
          返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。 
boolean isEmpty() 
          当且仅当 length() 为 0 时返回 true。 
int lastIndexOf(String str) 
          返回指定子字符串在此字符串中最右边出现处的索引。 
int lastIndexOf(String str, int fromIndex) 
          返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索。 
int length() 
          返回此字符串的长度。 
boolean matches(String regex) 
          告知此字符串是否匹配给定的正则表达式。 
String replace(CharSequence target, CharSequence replacement) 
          使用指定的字面值替换序列替换此字符串所有匹配字面值目标序列的子字符串。 
String replaceAll(String regex, String replacement) 
          使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串。 
String replaceFirst(String regex, String replacement) 
          使用给定的 replacement 替换此字符串匹配给定的正则表达式的第一个子字符。 
String[] split(String regex) 
          根据给定正则表达式的匹配拆分此字符串。 
String[] split(String regex, int limit) 
          根据匹配给定的正则表达式来拆分此字符串。 
boolean startsWith(String prefix) 
          测试此字符串是否以指定的前缀开始。 
boolean startsWith(String prefix, int toffset) 
          测试此字符串从指定索引开始的子字符串是否以指定前缀开始。 
String substring(int beginIndex) 
          返回一个新的字符串,它是此字符串的一个子字符串。 
String substring(int beginIndex, int endIndex) 
          返回一个新字符串,它是此字符串的一个子字符串。 
String toLowerCase() 
          使用默认语言环境的规则将此 String 中的所有字符都转换为小写。 
String toUpperCase() 
          使用默认语言环境的规则将此 String 中的所有字符都转换为大写。 
String trim() 
          返回字符串的副本,忽略前导空白和尾部空白。 
static String valueOf(int i) 
          返回 int 参数的字符串表示形式。

String(char[] value)
          分配一个新的 String,使其表示字符数组参数中当前包含的字符序列。

char[] toCharArray()
          将此字符串转换为一个新的字符数组。