Why doesn't my if condition work when I compare two strings?
Is there a different logic in Java for if statements when it comes to conditions? I mean my attempt to compare a String variable and a String attribute of a class that is on an array of objects was frustrated someway. It will not enter the if block. The two strings are equal. I displayed the values of each strings before the if evaluation and they are equal. The simbol I used was the ==, and I also tried the string.equals(string variable) as well as the
compareTo() == 0 option but none of those worked. I wish I knew what it is the way to compare two strings. Any advice will be appreciated. Thank you.:cool:
Re: Why doesn't my if condition work when I compare two strings?
Having example code would really help to figure out what is going on, but to help you do need to use the equals method when comparing two strings with each other.
Also note that "asdf" is not equal to "Asdf". They are case-sensitive.