8、startsWith()和endsWith(),startsWith()方法决定是否以特定字符串开始,endWith()方法决定是否以特定字符串结束
例:
String s1="this is my original string";
String sd="string";
s1.startsWith(sd); //返回 flase
s1.endsWith(sd); //返回 true
9、compareTo:比较
compareToIgnoreCase:比较,忽略大小写
如果参数字符串等于此字符串,则返回 0 值;如果按字典顺序此字符串小于字符串参数,则返回一个小于 0 的值;如果按字典顺序此字符串大于字符串参数,则返回一个大于 0 的值。
例:字典的顺序:0123456ABCabc 大写字母在小写字母前
String query = new String();
String number = new String();
int i = 0;
query = "a";
number = "1";
i = query.compareTo("A"); (a在A之后,返回大于0的值)
i = number.compareTo("2"); (1在2之前,返回小于0的值)