Summary of && and &

&& and & are both logical AND operators that both represent and. Generally, in the judgment process, the result is true only when the expressions on both sides of the operator are true. If one is not true, the result must be false, but && Also known as short-circuit and, it means that if the first expression is false in the process of judging the expression, then the subsequent expressions will not be judged, for example: String s = null; if(s != null && s.length()>5){} In this condition, the judgment of s.length()>5 will not be executed because s!=null is already false. & Must be executed before and after expressions. The use of && is to prevent reporting NullPointerException, such as the use of & in the example String s = null; if(s !=null & s.length()>5){}, the program will appear when the program is executed to s.length() Null pointer error.

Guess you like

Origin blog.csdn.net/limin322/article/details/29197115