Java Utililty Methods Object to Boolean

List of utility methods to do Object to Boolean

Description

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

Method

BooleanasBoolean(Object obj)
as Boolean
return asBoolean(obj, false);
BooleanasBoolean(Object obj)
as Boolean
Boolean result = Boolean.FALSE;
if (obj != null) {
    if (obj instanceof Boolean) {
        result = (Boolean) obj;
    } else if (obj instanceof String) {
        result = Boolean.valueOf("true".equalsIgnoreCase((String) obj) || 
                "1".equals((String) obj)); 
return result;
BooleanasBoolean(Object object)
return Object value as Boolean
if (object == null) {
    return null;
} else if (object instanceof Boolean) {
    return (Boolean) object;
} else if (object instanceof String) {
    return Boolean.valueOf((String) object);
return null;
...
BooleanasBoolean(Object value)
as Boolean
return Boolean.valueOf(asString(value));
booleanasBoolean(Object value)
convert a object value to boolean value.
if (value instanceof Boolean)
    return ((Boolean) value).booleanValue();
if (value instanceof Number) {
    return ((Number) value).intValue() > 0;
} else {
    String boolString = (String) value;
    return boolString != null && !boolString.equals("") && !boolString.equalsIgnoreCase("false");
booleanasBoolean(Object value)
as Boolean
if (value == null)
    throw new NullPointerException("value is null");
if (value instanceof Boolean) {
    return ((Boolean) value).booleanValue();
throw new IllegalArgumentException("not a boolean");
BooleancastBoolean(Object inObject)
cast Boolean
return castBoolean(inObject, null);
BooleancastBoolean(Object o)
cast Boolean
if (o instanceof Boolean) {
    return (Boolean) o;
} else if (o instanceof String) {
    try {
        return Boolean.parseBoolean((String) o);
    } catch (IllegalArgumentException e) {
        return null;
return null;
BooleancastBoolean(Object o)
cast Boolean
if (o == null) {
    return false;
} else if (o instanceof Boolean) {
    return (Boolean) o;
} else if (o instanceof String) {
    return ((String) o).equalsIgnoreCase("true") ? true : false;
} else {
    return false;
...
booleancastBoolean(Object o, boolean defaultValue)
cast Boolean
boolean booleanValue = defaultValue;
if (o != null) {
    booleanValue = Boolean.parseBoolean(castString(o));
return booleanValue;