Java Program to convert string type variables into boolean

In the following example of Java Program to convert string type variables into boolean .
Program :
public class Main {
    public static void main(String[] args) {

        // create a string variable
        String str = "true";

        // convert string to boolean using parseBoolean method
        boolean isTrue = Boolean.parseBoolean(str);

        System.out.println("String value: " + str);
        System.out.println("Boolean value: " + isTrue);
    }
}
Output :
String value: true
Boolean value: true
In this program, we first declare a string variable str and initialize it with the value "true".

We then convert this string variable into a boolean variable isTrue using the Boolean.parseBoolean() method. This method takes a string value as an argument and returns true or false depending on the value of the string.

Finally, we print both the string and boolean values using the System.out.println() method.