package string; public class lastIndexString { public static void main(String[] args) { /** * */ String str="hello I am ZHUXIAOPANG,welcomg to my blog,I think my blog will be better,hello blog"; int lastindex =str.lastIndexOf("blog"); if (lastindex == -1) { System.out.println("没有找到字符串最后出现的位置"); } else { System.out.println("字符串最后出现的位置在"+lastindex); } } }
最后输出结果