Skip to Content

Convert Java Boolean object to boolean primitive example

  1. /*
  2.   Convert Boolean Object to boolean primitive exmaple
  3.   This example show how a Boolean object can be converted to a boolean primitive
  4.   type.
  5. */
  6.  
  7. public class JavaBooleanTobooleanExample {
  8.  
  9.   public static void main(String[] args) {
  10.     //Construct a Boolean object.
  11.     Boolean blnObj = new Boolean("true");
  12.    
  13.     //use booleanValue of Boolean class to convert it into boolean primitive
  14.     boolean b = blnObj.booleanValue();
  15.     System.out.println(b);
  16.   }
  17. }
  18.  
  19. /*
  20. Output would be :
  21. true
  22. */