首页 > 编程 > Java > 正文

Java-基础 查找字符串最后一次出现的位置

2019-11-11 03:19:06
字体:
来源:转载
供稿:网友
/** * <PRe> * 作者:wangaw * 类说明:String常用操作-查找最后一次出现的位置 * 日期:2017年2月7日 * 备注: * </pre> */public class StringOp {    public static void main(String[] args) {        String strOrig = "Hello world ,Hello Run";        int lastIndex = strOrig.lastIndexOf("Hello");        if (lastIndex == -1) {            System.out.println("没有找到字符串 Run");        } else {            System.out.println("Run 字符串最后出现的位置: " + lastIndex);        }    }}

以上代码实例输出结果为:

Run 字符串最后出现的位置: 13
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表