java 常用类-String

1.string.indexOf(str);

  查找指定字符串在string中的第一次出现的索引。未找到返回-1.

String str1="012345";
String str2="23";
System.out.println( str1.indexOf(str2) );//2

2.string。indexOf(string str,int index);

  从索引index位开始,查找str在string中的索引位置。

String str1="012345012345";
String str2="23";
System.out.println( str1.indexOf(str2,5) );//8

猜你喜欢

转载自www.cnblogs.com/leizz/p/11563343.html