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(Object value)
to Boolean
if ((value == null || value instanceof Number && (((Number) value).longValue()) == 0L
        || value instanceof String && (value.equals("") || ((String) value).equalsIgnoreCase("false")
                || ((String) value).equalsIgnoreCase("no") || ((String) value).equalsIgnoreCase("0"))
        || value instanceof Boolean && value.equals(false))) {
    return false;
return true;
BooleantoBoolean(Object value, Boolean defaultValue)
to Boolean
return toBoolean(value, null, null, defaultValue);
booleantoBoolean(Object value, boolean defaultValue)
to Boolean
if (value == null) {
    return defaultValue;
} else {
    return toBoolean(value);
booleantoBoolean(String baseString)
to Boolean
return toBoolean(baseString, true);
booleantoBoolean(String content)
to Boolean
switch (content.toLowerCase().trim()) {
case "on":
case "true":
case "yes":
    return true;
case "off":
case "false":
case "no":
...
BooleantoBoolean(String flag)
Converts a one-char Y/N String to Boolean.
if ("Y".equals(flag)) {
    return true;
if ("N".equals(flag)) {
    return false;
throw new IllegalArgumentException("Flag should be Y/N");
booleantoBoolean(String input, boolean defaultValue)
to Boolean
if (input == null) {
    return defaultValue;
try {
    return Boolean.valueOf(input).booleanValue();
} catch (Exception e) {
    return defaultValue;
booleantoBoolean(String inString)
to Boolean
boolean retVal = false;
if (inString.toUpperCase().equals("Y") || inString.toUpperCase().equals("TRUE")
        || inString.equalsIgnoreCase("Yes")) {
    retVal = true;
} else if (inString.toUpperCase().equals("N") || inString.toUpperCase().equals("FALSE")
        || inString.equalsIgnoreCase("No")) {
    retVal = false;
return retVal;
booleantoBoolean(String propertyValue)
Converts the specified property value to a boolean.
return (propertyValue == null) ? false : Boolean.valueOf(propertyValue).booleanValue();
booleantoBoolean(String s)
returns the boolean equivalent of a string, which is considered true if either "on", "true", or "yes" is found, ignoring case.
return (s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("true") || s.equalsIgnoreCase("on")
        || s.equalsIgnoreCase("1"));