Convert Java Boolean Primitive to Boolean object


To convert Boolean Primitive to Boolean object, use the valueOf() method in Java.

Firstly, let us take a boolean primitive.

boolean val = false;

To convert it into an object, use the valueOf() method and set the argument as the boolean primitive.

Boolean res = Boolean.valueOf(val);

Let us see the complete example to learn how to convert Boolean Primitive to Boolean object.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      boolean val = false;
      // converting to object
      Boolean res = Boolean.valueOf(val);
      System.out.println(res);
   }
}

Output

False

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements