0
Can any body help me with this problem? It's on Oca book... the answer is (equal) but I don't know why...?
String a = ""; a += 2; a += 'c'; a += false; if ( a == "2cfalse") System.out.println("=="); if ( a.equals("2cfalse")) System.out.println("equals");
2 odpowiedzi
+ 1
In java, '==' compares refferences not content.
equals() method compares content(values)...
0
Because == is for comparing numbers.
For comparing String, we need to use the equals() method.
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html