Boolean.parseBoolean() in Java

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

Syntax:

boolean java.lang.Boolean.parseBoolean(String s)

This method takes one argument of type String as its parameter. This method parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".Otherwise, a false value is returned, including for a null argument. 

Example: 

1. Boolean.parseBoolean("True") returns true.

2. Boolean.parseBoolean("yes") returns false. 

Parameters: One parameter is required for this method.

s: the String containing the boolean representation to be parsed.

Returns: the boolean represented by the string argument.

For Example:

Boolean.parseBoolean("True") = > It returns true.

Approach

Java

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

        String s = "True";
        System.out.println(Boolean.parseBoolean(s));

    }
}

Output:

true

No comments:

Post a Comment