booleanValue()
is a built-in method of the boolean class in Java that is used to return a boolean object value as a primitive type boolean. We can call this method by using the class member access operator (.
) on the boolean class instance.
The built-in boolean class is available in the
java.lang
package in Java. This package is imported into every Java program by default.
boolean booleanValue()
booleanValue()
does not take any parameters.
boolean
: This method will only return either true
or false
.
In the example below, we have the EdPresso
class, which contains the main
method. By instantiating the boolean wrapper class as obj
, it will be possible to use this method.
Case#1: booleanValue()
calls the boolean object obj
and returns true
.
Case#2: booleanValue()
is called by the boolean object obj
and returns false
.
class EdPresso {// Main methodpublic static void main( String args[] ) {// Creating a Boolean object as TRUE.Boolean obj = new Boolean(true);// Extract primitive data typeboolean value = obj.booleanValue();// Print the resultSystem.out.println(value);}}