package web; public class text{ public static void main(String[]ages){ String str = "thinking in java"; //第一次出现的位置 int index = str.indexOf("in"); System.out.println(index); //最后一词出现的位置 index = str.lastIndexOf("in"); System.out.println(index); } } 第一次出现在第二的位置 最后一次出现在最后一个位置
|
|