+ 5
Need an explanation
public class Program { public static void main(String[] args) { String a = "a"; String b = "b"; String c = a + b; String d = "ab"; if (c==d) { System.out.println(1); } else { System.out.println(0); } } } Output: 0 Why?
4 Respostas
+ 4
Operator == in Java compares objects, but you need to compare just values of this objects. So to get correct result use .equals() method of String.
+ 3
== is used in java for reference comparsion. c and d in your code are different references.
+ 1
you need to compare strings using .equals()