String 的操作
字符串截取
String trim() 返回去掉字符串的首部后尾部的新字符串
split(String tegex)
split(String regex, limit) tegex:分割字符串的分割点 limit 分割成几个字符串
substring(beginIndex, endIndex) 包括beginIndex,不包括endIndex
toUpperCase() toLowerCase 分别是将字符串中的字母变成大写、小写
字符串比较 == 、equals() 、equalsIgnoreCase() 、compareTo() 、compareToIgnoreCase()、startsWith()、endsWith()
==是比较两个字符串的内存地址是否相同
equals 比较两个字符串的值是否相同
equalsIgnoreCase() 比较两个字符串的值且忽略大小写
boolean compareTo(String ) 按字典序比较
equalsIgnoreCase() 忽略大小写
boolean startsWith(String a) 是否以 a开头
boolean endsWith(String b) 是否以 b结尾
字符串查找
char charAt(int index) 返回指定索引处的字符
int indexOf(char a) 返回第一次出现a字符处的索引
int lastIndexOf(char a)返回最后一次出现a 字符处的索引
字符替换
String replace(char oldChar, char newChar)
String replaceFirst(String regex, String replacement) regex 被替换的字符串,替换的字符串 替换第一个匹配的字符串
String replaceAll(String regex, String replacement) 替换所有