Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is the booleanValue() method in Java?

AKASH BAJWA

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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);
        
    }
}

RELATED TAGS

java
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring