Java Program to convert Boolean to String

Java 8Object Oriented ProgrammingProgramming

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