+ 2
Why the answer is false?
int a = 1; System.out.println(++a==++a);
6 Respostas
+ 5
Because the output comparison will be: 2==3
And that is false :)
+ 3
In Java there are two ways of comparison for Strings. You use:
==, this means you check if (a+b) is the same object in the memory of your program as c. This is not the case so it will return false.
.equals, this is what you should have used to compare to Strings if they contain the same text. (a+b).equals (c) would have returned true. :)
+ 1
But, why in this case false again?
String a = "a";
String b = "b";
String c = "ab";
System.out.println((a+b)==c);
}}
//Output: false
+ 1
thanks, got it!
0
Exactly! Thank you!
0
what about this case?
public class Program
{
public static void main(String[] args) {
String a = "text";
String b = "text";
System.out.println(a==b);
}
}// Output: true