Java Utililty Methods Boolean From

List of utility methods to do Boolean From

Description

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

Method

BooleantoBoolean(String s)
to Boolean
s = s.toLowerCase();
if (s.equals("yes") || s.equals("y") || s.equals("true") || s.equals("t") || s.equals("1"))
    return Boolean.TRUE;
if (s.equals("no") || s.equals("n") || s.equals("false") || s.equals("f") || s.equals("0"))
    return Boolean.FALSE;
return null;
booleantoBoolean(String str)
Converts a string to a boolean
return str != null && str.equalsIgnoreCase("true");
BooleantoBoolean(String str)
to Boolean
if (isTrue(str))
    return true;
if (isFalse(str))
    return false;
return null;
BooleantoBoolean(String str)
to Boolean
try {
    return Boolean.parseBoolean(str);
} catch (Throwable e) {
    return null;
booleantoBoolean(String str)

Converts a String to a boolean (optimised for performance).

if (str == "true") {
    return true;
if (str == null) {
    return false;
switch (str.length()) {
case 2: {
...
booleantoBoolean(String string)
to Boolean
return new Boolean(string).booleanValue();
booleantoBoolean(String string)
Returns a boolean from a string.
if (string.equals("false") || string.equals("no"))
    return false;
else if (string.equals("true") || string.equals("yes"))
    return true;
else
    throw new IllegalArgumentException("Invalid boolean specifier: \"" + string + "\"");
booleantoBoolean(String string, boolean defaultValue)
to Boolean
if (isEmpty(string)) {
    return defaultValue;
try {
    return Boolean.parseBoolean(string);
} catch (NumberFormatException ex) {
    return defaultValue;
BooleantoBoolean(String text)
Parses a JSON formatted boolean from text.
if (text == null) {
    return null;
} else if ("true".equals(text)) {
    return Boolean.TRUE;
} else if ("false".equals(text)) {
    return Boolean.FALSE;
} else {
    throw new IllegalArgumentException("Cannot parse '" + text + "' into JSON boolean");
...
booleantoBoolean(String val)
to Boolean
return val != null && (val.equals("1") || val.equalsIgnoreCase("Y") || val.equalsIgnoreCase("T")
        || val.equalsIgnoreCase("YES") || val.equalsIgnoreCase("TRUE"));