public static void main(String[] args) {
Integer a = 1234567;
Integer b = 1234567;
System.out.println(a == b);
}
答案是false
public static void main(String[] args) {
Integer a = 1234567;
Integer b = 1234567;
System.out.println(a.equals(b));
}
答案是true
public static void main(String[] args) {
Integer a = 123;
Integer b = 123;
System.out.println(a == b);
}
答案是
true
public static void main(String[] args) {
Integer a = 123;
Integer b = 123;
System.out.println(a.equals(b));
}
答案是true
在工程上尽量使用Integer,Integer可以包含空,判断大于等于、小于等于用“==”和equals都可以。因此,在判断Integer等于时用equals。