Create a Boolean object from Boolean value in Java



To create a Boolean object from Boolean value is quite easy. Create an object with Boolean and set the Boolean value β€œtrue” or β€œfalse”, which are the Boolean literals.

Let us now see how β€œtrue” value is added.

Boolean bool = new Boolean("true");

In the same way, β€œFalse” value is added.

Boolean bool = new Boolean("false");

The following is an example displaying how to create a Boolean object from Boolean value.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      Boolean bool = new Boolean("true");
      System.out.println(bool);
      bool = new Boolean("false");
      System.out.println(bool);
   }
}

Output

True
False
Updated on: 2020-06-26T10:37:57+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements