public class Test { public static void main(String[] args) { String st1="大家好,大家加油"; //int length()获取当前字符串的长度 System.out.println(st1.length()); //char charAt(int index)获取指定索引位置的字符 System.out.println(st1.charAt(5)); //int indexOf(String)获取指定字符(串)第一次出现的索引 System.out.println(st1.indexOf("好")); //int lastIndexOf(String)获取指定字符(串)最后次出现的索引 System.out.println(st1.lastIndexOf("家")); //String substring(int)获取指定索引(含)之后的字符串 System.out.println(st1.substring(3)); //String substring(int,int)获取从索引start位置(含)起至索引end位置(不含)的字符串 System.out.println(st1.substring(1,4)); } }