我试图理解相等 (==) equals() 方法,但无法推断出这种行为。有人可以用以下 println 语句解释这种行为。
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
非常感谢。