java中String.indexOf()用法

查找指定字符或字符串在字符串中第一次出现地方的索引,未找到的情况返回 -1.

例如

String.indexOf(String str)

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

输出结果:2。

重载方法有

String.indexOf(String str,int index)

从index的地方开始找,返回第一次出现的索引

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

输出结果:8.

 

posted @ 2018-07-11 11:12  不爱熬夜的猫  阅读(54981)  评论(0编辑  收藏  举报