码迷,mamicode.com
首页 > 编程语言 > 详细

java integer String之equals vs ==

时间:2016-07-10 21:23:57      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

Integer a = new Integer(123);
Integer b = new Integer(123);

System.out.println(a == b);
System.out.println(a.equals(b));

System.out.println(a.equals(123));
System.out.println(a == 123);

输出

false
true
true
true

 

String a = new String("nihao");
String b = new String("nihao");

System.out.println(a==b);
System.out.println(a.equals(b));

System.out.println(a=="nihao");
System.out.println(a.equals("nihao"));

输出

false
true
false
true

 

java integer String之equals vs ==

标签:

原文地址:http://www.cnblogs.com/SEC-fsq/p/5658288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!