Java程序搜索一组字符的最后一个索引
使用该lastIndexOf()方法搜索一组字符的最后一个索引。假设以下是我们的字符串。
String myStr = "pqrstuvwxyzpqrst";
在字符串中搜索子字符串“pqrs”以获取其出现在字符串中的最后一个索引。我们从索引3开始搜索。
int begnIndex = 3;
strLastIndex = myStr.indexOf("pqrs", begnIndex);以下是一个示例,其中我们正在搜索子字符串“pqrs”的最后一个索引
示例
public class Demo {
public static void main(String[] args) {
String myStr = "pqrstuvwxyzpqrst";
int strLastIndex = 0;
System.out.println("String: "+myStr);
strLastIndex = myStr.lastIndexOf("pqrs");
System.out.println("字符串中子字符串pqrs的最后一个索引 "+myStr+" = "+strLastIndex);
}
}输出结果
String: pqrstuvwxyzpqrst 字符串中子字符串pqrs的最后一个索引 pqrstuvwxyzpqrst = 11
热门推荐
10 毛笔哥哥结婚祝福语简短
11 向国庆送祝福语简短
12 建队节祝福语简短
13 朋友喜得外孙简短祝福语
14 小店营业的祝福语简短
15 餐饮生日祝福语简短独特
16 鲜花英语祝福语卡片简短
17 男朋友暴富祝福语简短
18 婶婶拜年祝福语大全简短