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); } } |
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); } } |
false
public String toString()
Syntax
BooleanObject.toString()
Return Type: The returned value is 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 Boolean object Boolean b = new Boolean(true); // toString method of Boolean class String output = b.toString(); // printing the output System.out.println(output); } } |
true
Program 2:
// Java code to demonstrate // Boolean toString() method class GFG { public static void main(String[] args) { // creating Boolean object Boolean b = new Boolean(false); // toString method of Boolean class String output = b.toString(); // printing the output System.out.println(output); } } |
false
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- Java.lang.Short toString() method in Java with Examples
- Throwable toString() method in Java with Examples
- LinkedTransferQueue toString() method in Java with Examples
- LinkedBlockingQueue toString() Method in Java with Examples
- ShortBuffer toString() method in Java with Examples
- Provider toString() method in Java with Examples
- Java Signature toString() method with Examples
- Byte toString() method in Java with examples
- Scanner toString() method in Java with Examples
- StringBuilder toString() method in Java with Examples
- StringBuffer toString() method in Java with Examples
- Duration toString() method in Java with Examples
- Year toString() method in Java with Examples
- Matcher toString() method in Java with Examples
- Instant toString() method in Java with Examples
- LocalDateTime toString() method in Java with Examples
- LocalTime toString() method in Java with Examples
- ZonedDateTime toString() method in Java with Examples
- ZoneOffset toString() method in Java with Examples
- ZoneId toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

