user971741
user971741

Reputation:

String.equals don't return true even when it is

I have this small piece of simple code but I don't know why I can't get it to work:

tagName="Hello";
String value="Hello";
if (tagName!=null && tagName.equals(value))
{
    int io=0;
}

tagName is not null and clearly equals to value but the code never hits the line int io=0.

Upvotes: 0

Views: 108

Answers (1)

bmargulies
bmargulies

Reputation: 100051

Java may optimize out your assignment statement because it has no effect. You can put a System.out.println into that block, or you can move 'int io' to outside the if and just have an assignment inside the block.

Upvotes: 8

Related Questions