Boolean toString() Method in Java
Last Updated :
09 Apr, 2025
Improve
In Java, the toString() method of the Boolean class is a built-in method to return the Boolean value in string format. The Boolean class is a part of java.lang package. This method is useful when we want the output in the string format in places like text fields, console output, or simple text formatting.
Example 1: Using the Boolean.toString() method to get the object value in a string.
// Java program to demonstrate
// Boolean toString() method
class Geeks
{
public static void main(String[] args)
{
// boolean type value
boolean value = true;
// static toString() method of Boolean class
String output = Boolean.toString(value);
// printing the value
System.out.println(output);
}
}
Output
true
Syntax of toString(boolean b) Method
public static String toString(boolean b)
- Parameter: It takes a single boolean parameter (b) the value we want to convert into a string ( true or false ).
- Return: It returns a string representation of the boolean value passed in it ("true" or "false").
Example 2: Using Boolean.toString() method to convert false boolean value to its string representation.
// Java program to demonstrate
// Boolean toString() method
class Geeks
{
public static void main(String[] args)
{
// boolean type value
boolean value = false;
// static toString() method of Boolean class
String output = Boolean.toString(value);
// printing the value
System.out.println(output);
}
}
Output
false