Logical operator short-circuit effect in Java

Source: Internet
Author: User
Tags logical operators

In Java logical operators && and | |, they all have short-circuit effects.

For a && B, the entire expression is true only if both A and B are true (in Java, the expression A is first, and if A is true, the expression B is continued, and only A and B are true, the result is true)

If the expression A is false, the entire expression must also be false, so expression B is not calculated

For a | | b, the entire expression is false if both A and B are false (with one true, the expression is true)

If A is true, the value of the entire expression is true, there is no need to re-op expression b

So:

in Java, logical operators && and | | is known as short-circuit and short- circuit or

Logical operator short-circuit effect in Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.