I am trying to understand the equality (==) equals() method but couldn't reason out this behavior. Can someone explain this behavior with the following println statements.
String a="Hai";
String b="Hai";
int c=5, d=5;
System.out.println("Check1 : " + (c==d)); //prints "Check1 : true"
System.out.println("Check2 : " + a==b); //prints false. It didn't print the string "Check2 : "
System.out.println("Check3 : " +a.equals(b)); //prints "Check3 : true"
System.out.println(" c==d : " + c==d); //compile time error - incomparable types: java.lang.String and int
Many Thanks.