Home 类库下载 java类库 What is the difference between & and && in Java?

What is the difference between & and && in Java?

Mar 29, 2019 pm 03:20 PM


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.

What is the difference between & and && in Java?

[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);
Copy after login

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);
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)