【发布时间】:2015-01-12 03:57:40
【问题描述】:
我无法弄清楚为什么输出不同。
输出仅在 -128 到 127 范围内相同。
public class Check {
public static void main(String[ ] args) {
Integer i1=122;
Integer i2=122;
if(i1==i2)
System.out.println("Both are same");
if(i1.equals(i2))
System.out.println("Both are meaningful same");
}
}
输出:
两者都一样
两者意义相同
public class Check {
public static void main(String[] args) {
Integer i1=1000;
Integer i2=1000;
if(i1==i2)
System.out.println("Both are same");
if(i1.equals(i2))
System.out.println("Both are meaningful same");
}
}
输出: 两者意义相同
【问题讨论】:
-
总是使用等号。
-
这个问题有很多重复...一个简单的搜索就可以回答。