参考:
public class SearchString {
public static void main(String args[]) {
String Str1 = "https://www.csdn.net.csdn.net/" ;
String Str2 = "csdn",Str3 = "net" ;
System.out.println("n第一次的位置:"+ Str1.indexOf( "n" ) ) ;
//第一位以0开始计算,比如abcd的顺序是0123
System.out.println("n最后的位置:" + Str1.lastIndexOf( "n" ) ) ;
System.out.println("字符串Str2【"+ Str2 +"】最后的位置:" + Str1.lastIndexOf( Str2 ) ) ;
System.out.println("从第16个位置开始,n第一次的位置:" + Str1.indexOf( "n", 16 ) ) ;
//虽然从10开始,但是返回值依然是从开始计算
System.out.println("从第15个位置开始,字符串Str2【" + Str2 +"】第一次的位置:" + Str1.indexOf( Str2, 15 )) ;
System.out.println("字符串Str3【"+ Str3 +"】