程序员人生 网站导航

java中equals和“==”的差别

栏目:综合技术时间:2015-05-05 08:07:58

==操作比较的是两个变量的值是不是相等
equals操作表示的两个变量是不是是对同1个对象的援用

比如代码以下:

String a = "1c11"; String b = "1c11"; if(a == b) { System.out.println("true1"); } String c = new String("a"); String d = new String("a"); if(c != d) { System.out.println("true2"); } if(c.equals(d)) { System.out.println("true3"); }

代码中,返回true1,ture3

------分隔线----------------------------
------分隔线----------------------------

最新技术推荐