Java - What is the output:Equals address vs value

Question

What is the output of the following code.

public class Main {

  public static void main(String[] args) {
    System.out.println("abc" == "a"+"bc");
    System.out.println("abc" == new String("abc"));

    Integer a = new Integer(1);
    Integer b = new Integer(1);
    int aa = 1;
    int bb = 1;
    System.out.println(aa == bb);
    System.out.println(a == b);
    System.out.println(a.equals(b));

    System.out.println(Integer.MIN_VALUE);
  }

}


Click to view the answer

true
false
true
false
true
-2147483648

Demo

public class Main {

  public static void main(String[] args) {
    System.out.println("abc" == "a"+"bc");
    System.out.println("abc" == new String("abc"));

    Integer a = new Integer(1);
    Integer b = new Integer(1);
    int aa = 1;/*from  w ww  .j a va 2 s.  c o m*/
    int bb = 1;
    System.out.println(aa == bb);
    System.out.println(a == b);
    System.out.println(a.equals(b));

    System.out.println(Integer.MIN_VALUE);
  }

}

Related Exercise