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
truetruetrue
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
truefalsetrue