String类方法的使用2

String a = "你好";
        String b = "你好";
        boolean bool=a.equals(b);
        System.out.println(bool);
        String c = "AAAAAA";
        String d = "aaaaaa";
        boolean bool1=c.equalsIgnoreCase(d);
        System.out.println(bool1);
        

此为判断字符串是否相等 第一种区分大小写 第二种不区分大小写;

    String str1="你好";
        String str2="你好吗";
        boolean bool = str2.contains(str1);
        System.out.println(bool);
        boolean bool1 = str2.startsWith(str1);
        System.out.println(bool1);
        boolean bool2 = str2.endsWith("吗");
        System.out.println(bool2);

此代码为判断  是否包含字符串 是否以某个字符串开始  是否以某个字符串结束

原文地址:https://www.cnblogs.com/wangyufei123/p/8118849.html