总结一下学到的string类的获取功能中常用六中方法,更多的方法可以查询API
package String;
public class Test {
public static void main(String[] args) {
//方法一 获取字符串长度 应为9
String str="abca萌哒小丑鱼";
System.out.println(str.length());
//方法二 想要获得字符c
char ch=str.charAt(2);
System.out.println(ch);
//方法三 获取a第一出现的位置0
int index1=str.indexOf('a');
System.out.println(index1);
//方法三 获取a最后出现的位置3 应为abc
int index2=str.lastIndexOf('a');
System.out.println(index2);
//方法四 截取从第4个位置后面的字符应为:萌哒小丑鱼
String st1=str.substring(4);
System.out.println(st1);
//方法五 截取从0到3的字符
String st2=str.substring(0,3);
System.out.println(st2);
}
}