beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
    • Learn jQuery
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

Cast Boolean Object to boolean in Java – booleanValue() Method

By Chaitanya Singh | Filed Under: java.lang.Boolean

Description

Program to convert Boolean object to boolean primitive in java

Example

class BooleanObjToBooleanPrim {
	 
   public static void main(String[] args) {
      // Creating an object of Boolean Class
      Boolean bObj = new Boolean("true");
      // Case does not matter
      Boolean bObj2 = new Boolean("FaLsE");
	   
      /* Boolean object to boolean conversion 
       * using booleanValue() method
       */
      boolean bvar = bObj.booleanValue();
      System.out.println("boolean value is: "+bvar);
      boolean bvar2 = bObj2.booleanValue();
      System.out.println("boolean value is: "+bvar2);
  }
}

Output:

boolean value is: true
boolean value is: false

public boolean booleanValue(): Returns the value of this Boolean object as a boolean primitive. Source.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap