+ 2

Why I get false as output. Please explain

https://code.sololearn.com/cLJON9cPQ94j/?ref=app Why does it give false outpu as value and memory both are same of the String variable.

23rd May 2019, 3:33 AM
Ayush Pandey
Ayush Pandey - avatar
8 Respostas
+ 3
The (==) checks the equality of two primitive data type values since String is not primitive data type in Java we use the equals() function for it! your code must be like this: System.out.println(c.equals(d));
23rd May 2019, 4:56 AM
Abdol Hashimi
Abdol Hashimi - avatar
+ 2
Ayush Pandey Difference of String equality check? See the code and tell me why in first case both are equal Strings but in second case both are not equal Strings? String text1 = "ahmad"; String text2 = "ahmad"; text1.equals(text2); // returns true String text1 = "ahmad"; String text2 =new String("ahmad") ; text1.equals(text2); // returns false
23rd May 2019, 7:44 AM
Abdol Hashimi
Abdol Hashimi - avatar
+ 2
Eqbal Sharaf here you can get your answer, read all the answers and questions from start to end
28th May 2019, 8:45 AM
Abdol Hashimi
Abdol Hashimi - avatar
23rd May 2019, 5:32 AM
Ayush Pandey
Ayush Pandey - avatar
+ 1
Ayush Pandey this question is the answer of your question!
23rd May 2019, 7:44 AM
Abdol Hashimi
Abdol Hashimi - avatar
+ 1
Saboor Hakimi yes you r taking my question right
23rd May 2019, 8:37 AM
Ayush Pandey
Ayush Pandey - avatar
+ 1
Saboor Hakimi may be it is false cause one is variable and other is data type. Not quite sure. This topic to be honest is not quite clear yet.
23rd May 2019, 8:38 AM
Ayush Pandey
Ayush Pandey - avatar