What is the booleanValue() method in Java?

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.

Syntax


boolean booleanValue()

Parameters

booleanValue() does not take any parameters.

Return value

boolean: This method will only return either true or false.

Example

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 method
public static void main( String args[] ) {
// Creating a Boolean object as TRUE.
Boolean obj = new Boolean(true);
// Extract primitive data type
boolean value = obj.booleanValue();
// Print the result
System.out.println(value);
}
}

Free Resources