Android Utililty Methods String to Boolean Convert

List of utility methods to do String to Boolean Convert


The list of methods to do String to Boolean Convert are organized into topic(s).


StringgetValueOrDefault(String s, String s1)
get Value Or Default
String result = isEmpty(s).booleanValue() ? s1 : s;
return result;
booleantoBool(String str)
to Bool
try {
    return Boolean.parseBoolean(str);
} catch (Exception e) {
return false;
booleantoBoolean(final String value)
Returns true if the given string, when lower-cased, is exactly "true" or "yes".
if (isEmpty(value)) {
    return false;
String lc = value.toLowerCase(Locale.US);
return "true".equals(lc) || "yes".equals(lc);
booleangetBool(String str, boolean b)
get Bool
return null != str && str.equalsIgnoreCase("true") ? true : false;
booleantoBool(String b)
to Bool
try {
    return Boolean.parseBoolean(b);
} catch (Exception e) {
return false;
booleangetBooleanValue(String string)
Util method for retrieve a boolean primitive type from a String.
if ((string == null) || string.equals("")) {
    return false;
} else {
    if (StringUtil.equalsIgnoreCase(string, "true")) {
        return true;
    } else {
        return false;
booleanisTextBoolean(String texto)
is Text Boolean
boolean out = false;
if (texto != null) {
    texto = texto.toLowerCase().trim();
    if ("true".equals(texto) || "false".equals(texto)) {
        return true;
return out;
booleanparseBoolean(String string)
String must be 'true' - case insensitive to be true
return Boolean.parseBoolean(string == null ? "false" : string