The difference between & and &&, | and || in java

1. The & and && in the judgment statement both represent the AND operation.

The difference is that && means that as long as the first one of the two statements does not meet the conditions, it will be marked as an error and jump out of the judgment.

|| means that as long as the first one of the two statements meets the conditions, it will be marked directly and jump out of the judgment. | means that it is necessary to judge whether at least one of the two statements is correct

2、

        When they perform operations, & means that both numbers are first converted into binary, and then both numbers are 1 before they are 1, and the others are 0. | means that as long as one of the two numbers is 1, it is 1, and the others are 0

3. String s = null means that this s does not use a reference, so s.length() will throw a null pointer exception error
        String s = "" means that this s uses a reference, and the reference is "", so s.length()=0, without throwing a null pointer exception


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325685335&siteId=291194637