Home> Java> javaTutorial> body text

How to use boolean type in java?

coldplay.xixi
Release: 2020-07-02 13:48:53
Original
26396 people have browsed it

The usage of boolean type is the boolean [logical] data type in java. In java, boolean values can only be true and false, but cannot be replaced by 0 and 1, and must be lowercase. The code is [var myBoolean = new Boolean()].

How to use boolean type in java?

Usage of boolean type in java:

booleanisjava# The Boolean (logical) data type in ##, in Java, the boolean values can only be true and false, and cannot be replaced by 0 and 1, and must be lowercase.

Boolean value

truerepresents "true",falserepresents "false". General relational operators return Boolean results. In addition, numeric values 0, -0, special values null, NaN, undefined, and the null character ("") will be interpreted as false, and other values will be interpreted as true.

How to use boolean type in java?

Extended information

How to create a boolean object in java:

1. Use the keyword new to Define a Boolean object. The following code defines a logical object named myBoolean:

var myBoolean = new Boolean() var myBoolean = new Boolean()
Copy after login

Note: If the logical object has no initial value or its value is 0, -0, null, "", false, undefined, or NaN, then the object The value is false. Otherwise, its value is true (even when the argument is the string "false")!

2. All the following lines of code will create Boolean objects with an initial value of false.

var myBoolean = new Boolean(); var myBoolean = new Boolean(0); var myBoolean = new Boolean(null); var myBoolean = new Boolean(""); var myBoolean = new Boolean(NaN);
Copy after login

3. All the following lines of code will create Boolean objects with an initial value of true:

var myBoolean = new Boolean(1); var myBoolean = new Boolean(true); var myBoolean = new Boolean("true"); var myBoolean = new Boolean("false"); var myBoolean = new Boolean("Bill Gates");
Copy after login

Related learning recommendations:

Java Video Tutorial

The above is the detailed content of How to use boolean type in java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!