Java.lang.Boolean.toString() Method
Advertisements
Description
The java.lang.Boolean.toString() returns a String object representing this Boolean's value. If this object represents the value true, a string equal to "true" is returned. Otherwise, a string equal to "false" is returned.
Declaration
Following is the declaration for java.lang.Boolean.toString() method
public String toString()
Overrides
toString in class Object
Parameters
NA
Return Value
This method returns a string representation of this object.
Exception
NA
Example
The following example shows the usage of lang.Boolean.toString() method.
package com.tutorialspoint;
import java.lang.*;
public class BooleanDemo {
public static void main(String[] args) {
// create 2 Boolean objects b1, b2
Boolean b1, b2;
// assign values to b1, b2
b1 = new Boolean(true);
b2 = new Boolean(null);
// create 2 Strings s1, s2
String s1, s2;
// assign string value of objects b1, b2 to s1, s2
s1 = b1.toString();
s2 = b2.toString();
String str1 = "String value of boolean object " + b1 + " is " + s1;
String str2 = "String value of boolean object " + b2 + " is " + s2;
// print s1, s2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
Let us compile and run the above program, this will produce the following result:
String value of boolean object true is true String value of boolean object false is false