字符串操作:判断相等、判断首尾、大小写转换

判断是否相等:s.equals()

判断是否相等(忽略大小写):s.equalsIgnoreCase()

判断起始结尾:s.startsWith(),s.endsWith()

转大小写:s.toLowerCase(), s.toUpperCase()

        String s = "We are boys", s1 = "WE ARE BOYS";
        // 是否相等
        boolean b = s.equals(s1);
        boolean b1 = s.equalsIgnoreCase(s1);
        System.out.println("s是否等于s1:" + b + "\ns是否等于s1(忽略大小写):" + b1);
        //判断起始与结尾
        boolean b2 = s.startsWith("we");
        boolean b3 = s.endsWith("boys");
        System.out.println("s以“we”开始吗?" + b2 + "\ns以“boys”结束吗?" + b3);
        //转大小写
        String news1=s.toLowerCase();
        String news2=s.toUpperCase();
        System.out.println("小写:"+news1);
        System.out.println("大写"+news2);

posted @ 2017-08-08 19:11  夕西行  阅读(572)  评论(0编辑  收藏  举报