Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Boolean.toString() method is used to return 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.

Syntax

public String toString()

Parameters

No parameter is required.

Return Value

Returns a string representation of this object.

Exception

NA.

Example:

In the below example, the java.lang.Boolean.toString() method is used to return a String object representing the given Boolean's value.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Boolean object
    Boolean b1 = new Boolean(true);
    Boolean b2 = new Boolean(false);

    //printing the Boolean object 
    System.out.println("The b1 is: " + b1); 
    System.out.println("The b2 is: " + b2);

    //creating and printing the string representation
    //of the Boolean object's value
    System.out.println("The string value of b1 is: " + b1.toString()); 
    System.out.println("The string value of b2 is: " + b2.toString());   
  }
}

The output of the above code will be:

The b1 is: true
The b2 is: false
The string value of b1 is: true
The string value of b2 is: false

❮ Java.lang - Boolean