&& (short circuit and), &, | | (short circuit or), |, these operators are often used in Java program development, the following small series is mainly to introduce the difference between & and &&.
where && and & both represent logic and, when the result of the expression on both sides of the operator is true, the operation structure is true.
However, && has a short-circuit effect, and if the first expression is false, you do not have to judge the second expression.
Copy Code code as follows:
if ((str!=null) && (!str.equals ("")) {
SYSTEM.OUT.PRINTLN ("correct operation");
}
If you change && to & you throw a NullPointerException exception
The I value in if (2==1&++i) increases, and the I value inif (2==1&&++i) does not increase.
& can also do bitwise-and operation
|| and | How to use and && and & empathy
The above is the details of & and && the whole content of the difference, I hope to help you.