1.compareToIgnoreCase
方法用于按字典顺序(a < b)比较两个字符串,不考虑大小写
使用场景:
a.compareToIgnoreCase(b) == 0
********************** 代表a与b忽略大小写之后,值相同
2.replaceAll
urlEncode.replaceAll("%2B", "+").replaceAll("%26", " ");
用于Base64编码后的图片传输,将所有的"%2B"替换为"+",可以连续使用replaceAll,因为返回的是字符串。
3.startsWith
String str = "0123 56";
str.startsWith("0123");---------true
str.startsWith("56", 5);---------true --------下标5及其之后的字符串是否以“56”开头
4.indexOf
Java中字符串中子串的查找共有四种方法,如下:
int indexOf(String str) :返回第一次出现的指定子字符串在此字符串中的索引。
int indexOf(String str, int startIndex):从指定的索引处开始,返回第一次出现的指定子字符串在此字符串中的索引。
int lastIndexOf(String str) :返回在此字符串中最右边出现的指定子字符串的索引。
int lastIndexOf(String str, int startIndex) :从指定的索引处开始向后搜索,倒序遇到的第一个字符串的索引。
5.substring
substring (int beginIndex,int endIndex);----包括开始,不包括结尾