String类的判断功能(方法)

package cn.lgt.stringmethods;

public class StringJudgeMethods {
    public static void judgeMethods(){
        //String类的判断功能(方法)

        //1. 比较两个字符串的内容是否相同,区分大小写
        //boolean equals(Object obj);
        String s1 = "hello";
        String s2 = "world";
        String s3 = "hello";
        System.out.println(s1.equals(s2));
        System.out.println(s1.equals(s3));
        System.out.println(s2.equals(s3));
        System.out.println(s1.equals(s1));
        //2. 比较两个字符串的内容是否相同,忽略大小写
        //boolean equalsIgnoreCase(Object obj);
        String s4 = "HELLO";
        System.out.println("s1.equalsIgnoreCase(s4):" + s1.equalsIgnoreCase(s4));
        //3. 判断大字符串中是否包含小字符串
        //boolean contains(String str);
        String s5 = "helloworldhelloworld";
        System.out.println("s5.contains(s1):"+s5.contains(s1));
        //4. 判断字符串是否以某个指定的字符串开头
        //boolean startWith(String str);
        System.out.println("s5.startsWith(s1):"+s5.startsWith(s1));
        System.out.println("s5.startsWith(s2):"+s5.startsWith(s2));
        //5. 判断字符串是否以某个指定的字符串结尾
        //boolean endsWith(String str);
        System.out.println("s5.endsWith(s1): "+ s5.endsWith(s1));
        System.out.println("s5.endsWith(s2): "+ s5.endsWith(s2));
        //6. 判断字符串是否为空
        //boolean isEmpty();
        System.out.println("s5.isEmpty(): "+s5.isEmpty());
        String s6 = "";
        System.out.println("s6.isEmpty(): "+s6.isEmpty());
        //String s7 = null;
        //s7是一个空的指向,对一个对象做是否为空的判断,而s7没有创建对象,所以error
        //System.out.println("s7.isEmpty(): "+s7.isEmpty());
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值