Possible Duplicate:
Why do we usually use||not|, what is the difference?
Can I use single ampersand like & instead of a bitwise operator like &&? What kind of differences may arise and is there a specific example to illustrate this issue clearly?
The single
&will check both conditions always. The double&&will stop after the first condition if it evaluates to false. Using two is a way of “short circuiting” the condition check if you truly only need 1 condition of 2 to be true or false.An example could be:
If
myStringisnull, the first condition would fail and it would not bother to check the value of it. This is one way you can avoid null pointers.&and¦both operands are always evaluated&&and¦¦the second operand is only evaluated when it is necessaryHere’s a link to a page with a pretty good explanation of how to use these.
Java Quick Reference on Operators