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 小孩生日祝福语简短励志