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

String representation of Boolean in Java



To get the string representation of Boolean, use the toString() method.

Firstly, we have used the valueOf() method for Boolean object and set a string value.

Boolean val = Boolean.valueOf("false");

The same is then represented using “toString() method.

val.toString();

Let us see the complete example that prints the string representation of Boolean (True and False) in Java.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      // false
      Boolean val = Boolean.valueOf("false");
      System.out.println("Displaying the string representation of Boolean");
      System.out.println(val.toString());
      // true
      val = Boolean.valueOf("true");
      System.out.println(val.toString());
   }
}

Output

Displaying the string representation of Boolean
false
true
Updated on: 2020-06-26T10:03:36+05:30

558 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements