Java.lang.Boolean.booleanValue() Method

Advertisements


Description

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

Declaration

Following is the declaration for java.lang.Boolean.booleanValue() method

public boolean booleanValue()

Parameters

  • NA

Return Value

This method returns the primitive boolean value of this object.

Exception

  • NA

Example

The following example shows the usage of lang.Boolean.booleanValue() method.

package com.tutorialspoint;

import java.lang.*;

public class BooleanDemo {

   public static void main(String[] args) {

      // create a Boolean object b
      Boolean b;

      // assign value to b
      b = new Boolean(true);

      // create a boolean primitive type bool
      boolean bool;

      // assign primitive value of b to bool
      bool = b.booleanValue();

      String str = "Primitive value of Boolean object " + b + " is " + bool;

      // print bool value
      System.out.println( str );
   }
}

Let us compile and run the above program, this will produce the following result:

Primitive value of Boolean object true is true



Advertisements
Advertisements