Hi Friends......
I want to know,What can go wrong if you replace && with & in the following code:
String a=null; if (a!=null && a.length()>10) {...}
Thanks.........
Error In My Code
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 19, 2011, 6:33 PM EST
A single & will give a NullPointerException.
&& means that if the condition on the left is false it won't check looking at the condition on the right, if you use a single & instead it will force it to evaluate both conditions.
Thanks
Vikas MishraRank #559 · 4.3K reputationPosted Dec 20, 2011, 6:32 AM EST