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:
class GFG {
public static void main(String[] args)
{
boolean value = true ;
String output = Boolean.toString(value);
System.out.println(output);
}
}
|
Program 2:
class GFG {
public static void main(String[] args)
{
boolean value = false ;
String output = Boolean.toString(value);
System.out.println(output);
}
}
|
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:
class GFG {
public static void main(String[] args)
{
Boolean b = new Boolean( true );
String output = b.toString();
System.out.println(output);
}
}
|
Program 2:
class GFG {
public static void main(String[] args)
{
Boolean b = new Boolean( false );
String output = b.toString();
System.out.println(output);
}
}
|
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
03 Mar, 2021
Like Article
Save Article