Create a Boolean object from Boolean value in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 13-Nov-2018 05:28:22
Advertisements