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(final Object value, final boolean defaultValue)
to Boolean
final Boolean v = toBoolean(value);
return v == null ? defaultValue : v.booleanValue();
BooleantoBoolean(final Object valueRep)
to Boolean
return Boolean.parseBoolean(String.valueOf(valueRep));
booleantoBoolean(final String booleanString, final boolean defaultValue)
Retrieves whether the given value is true
return toBoolean(booleanString, TRUE, FALSE, defaultValue);
booleantoBoolean(final String s)
Convert a string into a boolean primitive (i.e.
String temp = s.toUpperCase();
return "TRUE".equals(temp) || "YES".equals(temp) || "ON".equals(temp);
booleantoBoolean(final String s)
to Boolean
return "true".equalsIgnoreCase(s) || "1".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s)
        || "enable".equalsIgnoreCase(s) || "yes".equalsIgnoreCase(s);
booleantoBoolean(final String source)
Returns true if the source string evaulates (case insensative and trimmed) to true, yes, or on.
return toBoolean(source, false);
StringtoBoolean(final String string)
to Boolean
return Boolean.valueOf(string).toString();
booleantoBoolean(final String strTransparent)
Parse a boolean from a string value.
if (strTransparent == null) {
    return false;
return Boolean.parseBoolean(strTransparent.trim());
ObjecttoBoolean(final String val)
to Boolean
if (val.equalsIgnoreCase("on")) {
    return Boolean.TRUE;
} else if (val.equalsIgnoreCase("off")) {
    return Boolean.FALSE;
return Boolean.parseBoolean(val);
BooleantoBoolean(final String value)
Convert a String to a boolean using the smart way
  • if the String is NULL, the Boolean will be NULL.
  • if the String can be cast to a long, the boolean will be TRUE if the long value is > 0, otherwise FALSE.
  • if the String is equal to "true", "yes" or "ok" the boolean will be TRUE.
  • if the String is equal to "false", "no" or "ko" the boolean will be FALSE.
  • all other cases will throw an IllegalArgumentException
  • if (value == null) {
        return null;
    if ("true".equals(value) || "yes".equals(value) || "ok".equals(value)) {
        return true;
    } else if ("false".equals(value) || "no".equals(value) || "ko".equals(value)) {
        return false;
    try {
        return Integer.valueOf(value) > 0;
    } catch (final NumberFormatException e) {
        throw new IllegalArgumentException(value + " is not a valid boolean value");