Boolean.toString() in Java

Boolean.toString(): This method is available in the java.lang.Boolean class of Java.

Syntax:

String java.lang.Boolean.toString(boolean b)

This method takes one argument of type boolean as its parameter. This method returns a String object representing the specified boolean. If the specified boolean is true, then the string "true" will be returned, otherwise the string "false" will be returned. 

Parameters: One parameter is required for this method.

b: the boolean to be converted.

Returns: the string representation of the specified boolean.

For Example:

Boolean.toString(true) = > It returns true.

Approach

Java

public class BooleantoString {
    public static void main(String[] args) {

        boolean b = true;
        System.out.println(Boolean.toString(b));

    }
}

Output:

true

No comments:

Post a Comment