I don't kno开发者_运维知识库w 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.
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.
==
is the identity comparison operator (same object). You should use equals()
when you want to compare equivalence.
Please use
CellType.equals("Hamster");
If you want to ignore case then use,
CellType.equalsIgnoreCase("Hamster");
CellType.equals("Hamster")
or
CellType.equalsIgnoreCase("Hamster")
Use the above formats, it will be taken care
精彩评论