1、字符串比较
equals() ——判断内容是否相同。
compareTo() ——判断字符串的大小关系。
compareToIgnoreCase(String int) ——在比较时忽略字母大小写。
== ——判断内容与地址是否相同。
equalsIgnoreCase() ——忽略大小写的情况下判断内容是否相同。
reagionMatches() ——对字符串中的部分内容是否相同进行比较(详情请参考API)。
2、字符串查找
charAt(int index) ——返回指定索引 index 位置上的字符,索引范围从 0 开始。
indexOf(String str)——从字符串开始检索str,并返回第一次出现的位置,未出现返回 -1。
indexOf(String str,int fromIndex);——从字符串的第 fromIndex 个字符开始检索 str。
lastIndexOf(String str)——查找最后一次出现的位置。
lastIndexOf(String str,int fromIndex)—-从字符串的第fromIndex个字符查找最后一次出现的位置。
starWith(String prefix,int toffset)—–测试此字符串从指定索引开始的子字符串是否以指定前缀开始。
starWith(String prefix)——测试此字符串是否以指定的前缀开始。
endsWith(String suffix)——测试此字符串是否以指定的后缀结束。
3、字符串截取
public String subString(int beginIndex)——返回一个新的字符串,它是此字符串的一个子字符串。
public String subString(int beginIndex,int endIndex)——返回的字符串是从 beginIndex 开始到 endIndex-1 的串。
4、字符串替换
public String replace(char oldChar,char newChar)。
public String replace(CharSequence target,CharSequence replacement)——把原来的 etarget 子序列替换为 replacement 序列,返回新串。
public String replaceAll(String regex,String replacement)——用正则表达式实现对字符串的匹配。注意 replaceAll 第一个参数为正则表达式,鄙人曾经深受其害。
5、更多方法请参考 API