Java的equals和==区别

Java的equals和==区别,第1张

Java的equals和==区别 Java的equals和==区别
public class EqualTest {
    public static void main(String[] args) {
        int a = 10;
        int b = 10;
        double c = 10.0;
        System.out.println(a == b);//true
        System.out.println(a == c);//true
        boolean f = true;
        //       System.out.println(a==f);
        char d = 10;
        System.out.println(a == d);//ture
        //引用数据类型
        Customer c1 = new Customer();
        Customer c2 = new Customer();
        System.out.println(c1 == c2);//false

        String s1=new String("tom");
        String s2=new String("tom");
        System.out.println("***********************");
        System.out.println(c1.equals(c2));//false
        System.out.println(s1.equals(s2));//true
    }
}
class Customer{

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5597759.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存