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 给外婆敬酒祝福语简短