Java Data Type How to - Get the string representation of a boolean








Question

We would like to know how to get the string representation of a boolean.

Answer

The static method toString() returns the string representation of a boolean:

 public static String toString (boolean boolean)
 
public class MainClass {

  public static void main(String[] args) {
    Boolean b = Boolean.valueOf("true");
    System.out.println(b.toString());
  }

}

The code above generates the following result.