String常用方法
1.int length()返回字符长度
2.char charAt(int index)返回索引处的字符
3.boolean isEmpty()判断是否是空字符串
4.String toLowerCase()将所有字符转为小写
5.String toUpperCase()将所有字符转为大写
6.String trim()忽略前后空白
7.boolean equals(Object obj)比较字符内容是否相同
8.boolean equalsIgnoreCase(String str)与上面方法类似,忽略大小写
9.String concat(String str)将指定字符添加到此字符串结尾。等价于+。
10.int compareTo(String str)比较两个字符串大小
String s1 = "abc";
String s2 ="abe";
int result = s1.compareTo(s2);
System.out.println(result);//c-e=-2
11.String substring(int beginIndex)返回一个新字符串,从beginIndex开始
12.String substring(int beginIndex,int endIndex),从beginIndex开始,从endIndex结束(左闭右开)
String str = "我爱中国";
System.out.println(str.substring(1));//爱中国
System.out.println(str.substring(1,2));//爱