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
热门推荐
7 简短的二胎祝福语
10 简短霸气女儿生日 祝福语
11 祝福语高考小众诗句简短
12 元旦祝福语20秒简短
13 老师过年祝福语大全 简短
14 一生祝福语简短
15 产检祝福语简短霸气
16 朋友店开张祝福语简短
17 生日爱情祝福语大全简短
18 朋友女儿生日祝福语 简短