boolean
This is the data type used for true/false conditions. To speed up memory access, implementations don't pack boolean values into the theoretical one-bit minimum space, but put each boolean into a byte.
example declaration:
boolean b = false;
range of values: false, true
literals: false true
In the code below,
boolean found = false;/* more code */if (x == 99) found = true;
x is compared with value 99. If x matches 99, then the boolean found is set to true.
You cannot assign or cast a boolean value to any other type. However, you can always get the same effect by using an expression, like the following:
if (b) i=1; else i=0; // set i according to boolean b value.// set boolean b according to int i valueif (i==1) b = true; else b = false; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access