Boolean to string in java

Java convert boolean to string using String.valueOf() method

package com.w3schools;

public class BooleanToString {
  public static void main(String args[]){
      boolean var = true;
      //convert boolean to string
      String str = String.valueOf(var);
      System.out.println("String is: "+str);
  }
}

Output:

String is: true

Download this example.

Java convert boolean to string using Boolean.toString() method

package com.w3schools;

public class BooleanToString {
  public static void main(String args[]){
       boolean var = true;
      //convert boolean to string
      String str = Boolean.toString(var);
      System.out.println("String is: "+str);
  }
}

Output:

String is: true

Download this example.