mardi 14 avril 2020

how if condition get executed in java if there are multiple condition separated by && and || operator [duplicate]

In my scenario : Refer below small code which throws null pointer exception

 String phdDelhi =null;
 if (!phdDelhi.equals("") && phdDelhi !=null && phdDelhi.equals("227")) 
       {
          //business logic
        }

but if i arrange the condition like below code, it will not throw exception

String phdDelhi =null;
 if (phdDelhi !=null && !phdDelhi.equals("") &&  phdDelhi.equals("227"))
     {
          //business logic
        }

So my concern is how it works at deeper level.? or simply i want to know the difference between above 2 codes and and their result behaviour.

Aucun commentaire:

Enregistrer un commentaire