Java program to convert string type variables into boolean

www.igif‮t‬idea.com

Sure, here's a Java program that converts string type variables into boolean:

public class StringToBooleanConverter {
    public static void main(String[] args) {
        String str1 = "true";
        String str2 = "false";
        
        boolean bool1 = Boolean.parseBoolean(str1);
        boolean bool2 = Boolean.parseBoolean(str2);
        
        System.out.println("bool1: " + bool1);
        System.out.println("bool2: " + bool2);
    }
}

In this program, we first create two string variables: str1 and str2.

We then use the Boolean.parseBoolean method to convert the strings to boolean values. This method returns true if the string is equal to "true" (ignoring case), and false otherwise.

Finally, we print out the boolean values of bool1 and bool2 to confirm that the conversion was successful.

Note that the Boolean.parseBoolean method is case-insensitive, so it will return true for strings like "True", "TRUE", or "tRuE".