以下实例中我们通过字符串函数 strorig.lastindexof(stringname) 来查找子字符串 stringname 在 strorig 出现的位置:
实例代码如下:
//SearchlastString.java 文件public class SearchlastString {
public static void main(String[] args) {
String strOrig = "Hello world ,Hello Reader";
int lastIndex = strOrig.lastIndexOf("Hello");
if(lastIndex == - 1){
System.out.println("Hello not found");
}else{
System.out.println("Last occurrence of Hello
is at index "+ lastIndex);
}
}}以上代码实例输出结果为:
Last occurrence of Hello is at index 13
以上就是Java 实例 - 查找字符串最后一次出现的位置的内容,更多相关内容请关注PHP中文网(www.php.cn)!
立即学习“Java免费学习笔记(深入)”;
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号