浅谈Java中的==与equals

2018-12-12  本文已影响0人  Stefango
public class HelloWorld {
    public static void main(String[] args) {
        
        //基本数据类型int
        int a = 0;
        int b = 0;
        System.out.println(a == b); //true
        
        //引用数据类型String
        String c = new String("hello");
        String d = new String("hello");
        System.out.println(c == d); //false
        System.out.println(c.equals(d)); //true
        
        String e = "world";
        String f = "world";
        System.out.println(e == f); //true
        System.out.println(e.equals(f)); //true
    }
}
// 参考https://www.cnblogs.com/dolphin0520/p/3592500.html
上一篇下一篇

猜你喜欢

热点阅读