我最好的代码片段:Integer类对象
public class Test{
public static void main(String args[]){
Integer a = 100;
Integer b = 100;
Integer c = 5000;
Integer d = 5000;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
if(a == b)
System.out.println("a & b Both are Equal");
else
System.out.println("a & b are Not Equal");
if(c == d)
System.out.println("c & d Both are Equal");
else
System.out.println("c & d are Not Equal");
}
}
我没有得到为什么输出是这样的吗? 的Output
是:
a & b Both are equal
c & d are not equal
我使用jdk1.7
**当equals()为真时,对象**只有“相等”。使用'=='表示**引用**是相同的。 –