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.

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM