我想了解等于(==)equals()方法,但无法推理出这种行为。 有人可以用下面的println语句解释这种行为。Java:equals()和=== String和int变量
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
很多谢谢。
你确定'一== B'打印'FALSE'? – user2004685