package wfh7_21;
public class index {
public static void main(String[] args) {
String str1 = "abcdefg";
int x = str1.indexOf("c");
int y = str1.indexOf("de");
//从0开始算起
System.out.println(x+" "+y);//"c"和"de"的所在位置
}
}
方法: 字符串.indexOf("字符或字符串") //从第一个字符开始算起
结果截图: