How to convert String object to Boolean Object?
To convert a String object to a Boolean object in Java, you can use the Boolean.valueOf method:
To convert a String object to a Boolean object in Java, you can use the Boolean.valueOf method:
String str = "true";
Boolean bool = Boolean.valueOf(str); // bool is now a Boolean object with the value trueThis method returns a Boolean object with the value true if the string is equal to "true" (ignoring case). For any other string, including null, it returns a Boolean object with the value false. It never throws an exception.
Alternatively, you can use the Boolean.parseBoolean method:
String str = "true";
boolean bool = Boolean.parseBoolean(str); // bool is now a boolean primitive with the value trueThis method returns a boolean primitive with the value true if the string is equal to "true" (ignoring case). For any other string, including null, it returns false.
You can also use the Boolean.getBoolean method to get the boolean value of a system property:
String str = "java.awt.headless";
boolean bool = Boolean.getBoolean(str); // bool is now the boolean value of the system property "java.awt.headless"This method returns the boolean value of the system property with the specified name. If the property name is null, or if the system property does not exist or its value is not equal to "true" (ignoring case), it returns false.