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()].
Usage of boolean type in java:
boolean
is java# 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.
true represents "true",
false represents "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.
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()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);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");
Related learning recommendations:
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!