/java/

Java autoboxing example1

2013-10-14 19:56:05

        Integer e = 127;
        Integer r = 127;

        System.out.print("Integer=127 == Integer=127: ");
        System.out.println(e == r);

        Integer x = new Integer(127);
        Integer y = new Integer(127);

        System.out.print("Integer (127) == Integer (127): ");
        System.out.println(x == y);

        Integer a = new Integer(129);
        Integer b = new Integer(129);

        System.out.print("Integer 129 == Integer 129: ");
        System.out.println(a == b);

        Integer t = 129;
        Integer u = 129;

        System.out.print("Integer=129 == Integer=129: ");
        System.out.println(t == u);

        System.out.print("Integer == 129: ");
        System.out.println(a == 129);

        Boolean BTrue1 = new Boolean(true);
        Boolean BTrue2 = new Boolean(true);

        System.out.print("Boolean == Boolean: ");
        System.out.println(BTrue1 == BTrue2);

        boolean bTrue = true;
        System.out.print("Boolean == boolean: ");
        System.out.println(BTrue1 == bTrue);

        String s1 = new String("lorem");
        String s2 = new String("lorem");
        System.out.print("String == String: ");
        System.out.println(s1 == s2);

        System.out.print("String == 'lorem': ");
        System.out.println(s1 == "lorem");

        System.out.print("String equals 'lorem': ");
        System.out.println(s1.equals("lorem"));

Integer=127 == Integer=127: true Integer (127) == Integer (127): false Integer 129 == Integer 129: false Integer=129 == Integer=129: false Integer == 129: true Boolean == Boolean: false Boolean == boolean: true String == String: false String == 'lorem': false String equals 'lorem': true