Java Program to convert Boolean to String


To convert Boolean to String in Java, use the toString() method. For this, firstly, we have declared two booleans.

boolean bool1 = false;
boolean bool2 = true;

Now, convert Boolean to String using the toString() method in Java as shown below −

String str1 = new Boolean(bool1).toString();
String str2 = new Boolean(bool2).toString();

Now, when you will display the values “str1” and “str2”, the output would be in String.

Let us now see the complete example to convert Boolean to String.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      boolean bool1 = false;
      boolean bool2 = true;
      String str1 = new Boolean(bool1).toString();
      String str2 = new Boolean(bool2).toString();
      System.out.println(str1);
      System.out.println(str2);
   }
}

Output

false
true

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements