如下测试代码:
public class TestEquals { public static void main(String[] args) { Long l1 = 1L; Long l2 = 1L; Long l3 = new Long(1); Long l4 = new Long(1); System.out.println("long 开始=============="); System.out.println(l1 == l2); System.out.println(l1 == l3); System.out.println(l3 == l4); System.out.println("long 结束=============="); String s1 = "a"; String s2 = new String("a"); String s3 = new String("a"); System.out.println("String == 开始=============="); System.out.println("a" == s1); System.out.println(s1 == s2); System.out.println(s2 == s3); System.out.println("String == 结束=============="); System.out.println("String equals 开始=============="); System.out.println(s1.equals("a")); System.out.println(s1.equals(s2)); System.out.println(s2.equals(s3)); System.out.println("String equals 结束=============="); } } long 开始============== true false false long 结束============== String == 开始============== true false false String == 结束============== String equals 开始============== true true true String equals 结束==============