Convert boolean Primitive to Boolean object - Java Language Basics

Java examples for Language Basics:boolean

Description

Convert boolean Primitive to Boolean object

Demo Code

public class Main {
 
  public static void main(String[] args) {
    boolean b = true;
   //from   w  ww  . j  av  a  2  s .c o m
    //1. using constructor
    Boolean blnObj1 = new Boolean(b);
   
    //2. using valueOf method of Boolean class. This is a static method.
    Boolean blnObj2 = Boolean.valueOf(b);
  }
}

Related Tutorials