xxxxxxxxxx
def str2bool(v):
return v.lower() in ("yes", "true", "t", "1")
xxxxxxxxxx
String value = "true";
boolean b = Boolean.parseBoolean(value);
System.out.println(b);
Read more: https://www.java67.com/2018/03/java-convert-string-to-boolean.html#ixzz6HF3C1ERb
xxxxxxxxxx
def convert_to_bool(string):
string_lower = string.lower()
if string_lower == 'true':
return True
elif string_lower == 'false':
return False
else:
raise ValueError('Invalid boolean string')
# Example usage
string_value = 'True'
bool_value = convert_to_bool(string_value)
print(bool_value)
xxxxxxxxxx
boolean boolAnswer;
//answer represents the string you want to convert to boolean
String answer;
answer = "yes";
//compares given variable (answer) to defined true value (yes).
boolAnswer = answer.equals("yes"); //boolAnswer is true
answer = "no" //or anything that isn't "yes", including null
boolAnswer = answer.equals("yes") //boolAnswer is false