Java.lang Package Classes

Java Boolean - booleanValue() Method



The java.lang.Boolean.booleanValue() method returns the value of this Boolean object as a boolean primitive.

Syntax

public boolean booleanValue()

Parameters

No parameter is required.

Return Value

Returns the primitive boolean value of this object.

Exception

NA.

Example:

In the example below, the java.lang.Boolean.booleanValue() method returns a Boolean object after conversion to type boolean.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Boolean objects
    Boolean b1 = true;
    Boolean b2 = false;

    //printing booleanValue of the Boolean objects
    System.out.println("booleanValue of the b1 is: " + b1.booleanValue()); 
    System.out.println("booleanValue of the b2 is: " + b2.booleanValue());   
  }
}

The output of the above code will be:

booleanValue of the b1 is: true
booleanValue of the b2 is: false

❮ Java.lang - Boolean

5