Java Program to convert boolean value to Boolean

Java 8Object Oriented ProgrammingProgramming

Use the valueOf() method to convert boolean value to Boolean. Firstly, let us take a boolean value.

boolean val = false;

Now, to convert it to Boolean object, use the valueOf() method.

Boolean res = Boolean.valueOf(val);

Let us now see the complete example to convert boolean value to Boolean.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      boolean val = false;
      System.out.println("Boolean Value = "+val);
      Boolean res = Boolean.valueOf(val);
      System.out.println("Boolean = " + res);
      if (res.equals(Boolean.TRUE)) {
         System.out.println("Boolean = " + res);
      } else {
         System.out.println("Boolean = " + res);
      }
   }
}

Output

Boolean Value = false
Boolean = false
Boolean = false
raja
Published on 13-Nov-2018 12:00:57
Advertisements