包装类

import java.io.File;
import java.io.FileReader;

/**
 * 包装类
 * 详解:http://alexyyek.github.io/2014/12/29/wrapperClass/
 */
public class WrappClassTest {
    public static void main(String[] args) {
        Integer a = 1;
        Integer b = 2;
        Integer c = 3;
        Integer d = 3;
        Integer e = 200;
        Integer f = 200;
        Long g = 3L;
        Long h = 2L;

        System.out.println("c == d -> " + (c == d));
        System.out.println("e == f -> " + (e == f));
        System.out.println("c == (a + b) -> " + (c == (a + b)));
        System.out.println("c.equals(a + b) -> " + (c.equals(a + b)));
        System.out.println("g == (a + b) -> " + (g == (a + b)));
        System.out.println("g.equals(a + b) -> " + (g.equals(a + b)));
        System.out.println("g.equals(a + h) -> " + (g.equals(a + h)));


        String s1 = "ab";
        String s2 = "a" + "b";
        String s4 = new String("ab");
        String s5 = new String("ab");
        String str1 = "a";
        String str2 = "b";

        String s3 = str1 + str2;
        System.out.println(s1 == s2);
        System.out.println(s1 == s3);
        System.out.println(s3);
        System.out.println(s1 == s4);
        System.out.println(s5 == s4);
        System.out.println(s5.equals(s4));
        System.out.println(s5.hashCode() == s4.hashCode());


    }
}

结果

c == d -> true
e == f -> false
c == (a + b) -> true
c.equals(a + b) -> true
g == (a + b) -> true
g.equals(a + b) -> false
g.equals(a + h) -> true
true
false
ab
false
false
true
true
原文地址:https://www.cnblogs.com/dayaodao/p/8697136.html