Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

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
Updated on: 2020-06-26T10:38:52+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements