以下实例中我们通过字符串函数 strOrig.lastIndexOf(Stringname) 来查找子字符串 Stringname 在 strOrig 出现的位置:
实例代码如下:
public class SearchlastString {
public static void main(String[] args) {
String strOrig = "Hello world ,Hello itzixishi";
int lastIndex = strOrig.lastIndexOf("itzixishi");
if(lastIndex == - 1){
System.out.println("没有找到字符串 itzixishi");
}else{
System.out.println("itzixishi 字符串最后出现的位置: "+ lastIndex);
}
}
}
以上代码实例输出结果为:
itzixishi 字符串最后出现的位置: 19
©2020 IT自习室京ICP备20010815号