Friday, September 5, 2025
HomeLanguagesJavaBoolean toString() method in Java with examples

Boolean toString() method in Java with examples

The toString() method of Boolean class is a built in method to return the boolean value in string format.

There are 2 overloads of toString() methods in Boolean class of Java:

public static String toString(boolean value)

Syntax

Boolean.toString(boolean value)

Parameter: It takes a boolean value as input which is to be converted to string.

Return Type: The returned value is String representation of the Boolean Value.

Below are programs to illustrate toString() method:

Program 1:




// java code to demonstrate
// Boolean toString() method
  
class GFG {
    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

Program 2:




// java code to demonstrate
// Boolean toString() method
  
class GFG {
    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

public String toString()

Syntax

BooleanObject.toString()

Return Type: The returned value is a String representation of the boolean instance by which this method is called.

Below are programs to illustrate above defined method:

Program 1:




// java code to demonstrate
// Boolean toString() method
  
class GFG {
    public static void main(String[] args)
    {
  
        // creating a Boolean object
        Boolean b = new Boolean(true);
  
        // toString method of Boolean class
        String output = b.toString();
  
        // printing the output
        System.out.println(output);
    }
}


Output:

true

Program 2:




// Java code to demonstrate
// Boolean toString() method
  
class GFG {
    public static void main(String[] args)
    {
  
        // creating a Boolean object
        Boolean b = new Boolean(false);
  
        // toString method of Boolean class
        String output = b.toString();
  
        // printing the output
        System.out.println(output);
    }
}


Output:

false
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6636 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11865 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7026 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS