Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Convert boolean primitive to Boolean Object example

  1. /*
  2.  * Convert boolean primitive to Boolean Object example. Program to convert Java
  3.  * boolean primitive data type to Boolean object.
  4.  */
  5.  
  6. public class booleanPrimitiveToBoolean {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new boolean primitive
  11.   boolean b = false;
  12.  
  13.   //Use Boolean(boolean b) constructor
  14.   Boolean bObj1 = new Boolean(b);
  15.  
  16.   //Use static valueOf method of Boolean class
  17.   Boolean bObj2 = Boolean.valueOf(b);
  18.  
  19.   System.out.println("boolean pritive converted to Boolean: " + bObj1);
  20.  
  21.  }
  22. }
No votes yet
Share this

Post new comment

1 + 9 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.