开发者

Strange String comparation

I don't kno开发者_运维知识库w why the comparation of CellType to "Hamster" is false. Wonder why it happened!

Strange String comparation

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜