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 obj)
to Boolean
if (isNull(obj)) {
    return getNull();
if (obj instanceof Boolean) {
    return (Boolean) obj;
if ("true".equalsIgnoreCase(obj.toString())) {
    return Boolean.TRUE;
...
booleantoBoolean(Object obj)
Converts an object to boolean, according to the following logic:
  1. If it's null, false is returned.
  2. If it's a Boolean, the same object is returned.
  3. If it's any other object, the toString() value is converted to boolean.
if (obj != null) {
    if (obj instanceof Boolean) {
        return (Boolean) obj;
    } else {
        return toBoolean(obj.toString());
} else {
    return false;
...
BooleantoBoolean(Object obj)
Converts an Object to a Boolean.
if (obj instanceof Boolean) { 
    return (Boolean) obj;
} else if (obj instanceof String) {
    return Boolean.valueOf((String) obj);
} else if (obj == null) {
    return null;
} else {
    return Boolean.FALSE;
...
booleantoBoolean(Object obj)
to Boolean
try {
    if (obj instanceof String) {
        if (obj.equals("true") || obj.equals("yes")) {
            return true;
        return false;
    } else if (obj instanceof Integer) {
        return ((Integer) obj).intValue() == 1;
...
booleantoBoolean(Object object)
Converts an object to a boolean (return false if the conversion fail)
if (object instanceof Boolean) {
    return ((Boolean) object).booleanValue();
} else if (object instanceof String) {
    return Boolean.parseBoolean((String) object);
} else {
    return false;
booleantoBoolean(Object object)
to Boolean
if (object instanceof Boolean) {
    return ((Boolean) object).booleanValue();
if (object instanceof Number) {
    return ((Number) object).intValue() != 0;
return object != null;
BooleantoBoolean(Object object)
to Boolean
Boolean b = null;
if (object != null) {
    if (object instanceof Boolean)
        b = (Boolean) object;
return b;
booleantoBoolean(Object object)
to Boolean
if (object.equals(Boolean.TRUE)
        || (object instanceof String && (((String) object).equalsIgnoreCase("true"))
                || ((String) object).equalsIgnoreCase("1"))
        || ((object instanceof Number) && (((Number) object).intValue() == 1))) {
    return true;
return false;
BooleantoBoolean(Object object, Boolean defaultValue)
to Boolean
if (object == null) {
    return defaultValue;
if (object instanceof Boolean) {
    return ((Boolean) object).booleanValue();
try {
    Boolean value = Boolean.valueOf(object.toString().trim());
...
booleantoBoolean(Object property, boolean defaultValue)
to Boolean
if (property == null) {
    return defaultValue;
return Boolean.parseBoolean(String.valueOf(property));