The difference between & and && in Java is: in the && operation, when the first expression is false, the following expression will not be executed; while the & operation Regardless of whether the first expression is true or not, the latter expression will be executed
In Java, && and & are both logical operators representing "and", which means and. They are all true when the expressions on both sides are true, and the entire operation result is true, otherwise it is false. Next, in the article, we will introduce the differences between the two in detail, which will serve as a reference and I hope it will be helpful to everyone.
[Recommended course: Java Tutorial]
The difference between & and &&
& and && are both logical operation symbols, but && is also called a short-circuit operator. Because when the value of the first expression is false, the second expression will not be evaluated;
and & will execute both expressions regardless of whether the first expression is true. In addition, & can also be used as a bitwise operator. When the expressions on both sides of & are not of Boolean type, & represents a bitwise operation.
&& Operation
int i = 0; if(i == 3 && ++i > 0 ) { } System.out.println("i = " + i);
The result is: i = 0 ==>The second expression is not executed
& Operation
int i = 0; if(i == 3 & ++i > 0 ) { } System.out.println("i = " + i);
The result is: i = 1 ==>The second expression is executed
Summary: The above is all of this article The content is here, I hope it will be helpful to everyone
The above is the detailed content of What is the difference between & and && in Java?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
