java - Is there any difference between == null and .equals("null")? -


i confused following code. why compare both == , equals method?

(validfolderrow.getbondtafoldertype() == null || validfolderrow.getbondtafoldertype().equals("null")) 

what's difference between equals() , ==?

can tell me difference between

validfolderrow.getbondtafoldertype() == null 

and

validfolderrow.getbondtafoldertype().equals("null") 

?

validfolderrow.getbondtafoldertype() == null compares null (i.e. checks if validfolderrow.getbondtafoldertype() null). validfolderrow.getbondtafoldertype().equals("null") compares validfolderrow.getbondtafoldertype() string value "null".

note first comparison must done first, since if validfolderrow.getbondtafoldertype() null, can't call equals on (since throw nullpointerexception). since || short circuit operator, evaluating first operand true prevent second operand being evaluated.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -