7.12 字符串查找

  • contains indexOf, lastIndexOf,startsWith,endWith
public class HelloWorld {
    public static void main(String args[]){// String args[]字符串数组的意思

        String str = "www.mldn.cn";
        System.out.println(str.contains("mldn"));//true
        System.out.println(str.indexOf("mldn"));//4
        System.out.println(str.indexOf("hello"));//-1
        System.out.println(str.lastIndexOf("."));//8
        System.out.println(str.lastIndexOf(".",5));//3,从第5个开始查;

        System.out.println("---------------");
        String str2 = "**@@www.mldn.cn##";
        System.out.println(str2.startsWith("**"));//true
        System.out.println(str2.startsWith("**",2));// false ,从第2个开始判断;
        System.out.println(str2.endsWith("##"));//true

    }

}

posted @ 2023-06-06 22:39  盘思动  阅读(5)  评论(0编辑  收藏  举报