Java Boolean class

The Boolean class wraps a value of the primitive type boolean in an object. Its object contains only a single field whose type is boolean.

Methods

MethodsDescription
booleanValue()Returns a Boolean primitive for the value of this Boolean object.
compare()Compares two Boolean values.
compareTo()Compares this Boolean instance with another.
equals()Returns a Boolean value true if the argument is a Boolean object that represents the same value as this object.
getBoolean()Returns a Boolean value true if the system property name is equal to the string "true".
hashCode()Returns a hash code for the Boolean object.
logicalAnd()Returns the result of implementing logical AND operation on the assigned boolean operands.
logicalOr()Returns the result of implementing logical OR operation on the assigned boolean operands.
logicalXor()Returns the result of implementing logical XOR operation on the assigned boolean operands.
parseBoolean()Parses the string argument as a Boolean.
toString()Returns a String instance representing the specified Boolean's value or the specified boolean.
valueOf()Returns a Boolean instance representing the specified Boolean value or string value.

Example 1

Test it Now

Output:

Value of boolean object true is true.
b1 is true.
Logical And will return false

Example 2

Test it Now

Output:

Boolean value = true
Hash Code for boolean value = 1231
String value = true
Hash Code for String Value = 3569038
valueOf() method will return = true
value of val is true

Next TopicJava Boolean




Latest Courses