+ 3
What will be the output for following java code snippet :
public static void main(String args [ ]) { String str= new String("Alan"); String str1="Alan"; if(str==str1) { System.out.println("True"); } else System.out.println("False"); }
5 odpowiedzi
+ 4
False.. Don't use == to compare strings.. Use equals.() instead
if(str.equals(str1))
+ 7
well you will understand this by this post go through this
https://www.sololearn.com/Discuss/647021/?ref=app
+ 3
It is not comparing the strings there it is actually comparing the address of the strings where they are stored and hence that is why I have not used .equals in my if statement..
0
so you don't have a question about the code u sent. right?
0
1