Reputation: 20748
I don't know why the comparation of CellType to "Hamster" is false. Wonder why it happened!
They are exactly the same, even in case sensitive.
Please help me.
Upvotes: 0
Views: 238
Reputation: 70949
You need to use
if (CellType.equals("Hamster")) {
...
}
The other comparison checks to see if they are the same string Object, not the same string by value.
It is also a good time to lookup the differences between reference equality and Object equality.
Upvotes: 4
Reputation: 15960
CellType.equals("Hamster")
or
CellType.equalsIgnoreCase("Hamster")
Use the above formats, it will be taken care
Upvotes: 0
Reputation: 4454
Please use
CellType.equals("Hamster");
If you want to ignore case then use,
CellType.equalsIgnoreCase("Hamster");
Upvotes: 0
Reputation: 17341
==
is the identity comparison operator (same object). You should use equals()
when you want to compare equivalence.
Upvotes: 0