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

boolean[]toBooleanArray(final Object[] array)
to Boolean Array
if (array == null) {
    return new boolean[0];
final boolean[] retVal = new boolean[array.length];
try {
    for (int i = 0; i < array.length; i++) {
        retVal[i] = Boolean.parseBoolean(String.valueOf(array[i]));
    return retVal;
} catch (Exception e) {
    return new boolean[0];
boolean[]toBooleanArray(int[] intArray, int n)
to Boolean Array
boolean[] array = new boolean[n];
for (int element : intArray) {
    array[element] = true;
return array;
boolean[]toBooleanArray(Object[] vs)
to Boolean Array
boolean[] nvs = new boolean[vs.length];
for (int i = 0; i < vs.length; i++) {
    nvs[i] = (boolean) vs[i];
return nvs;
booleantoBooleanDefaultIfNull(Boolean bool, boolean valueIfNull)
to Boolean Default If Null
if (bool == null) {
    return valueIfNull;
return bool;
booleantoBooleanDefaultIfNull(Boolean bool, boolean valueIfNull)

Converts a Boolean to a boolean handling null.

 BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, false) = true BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, true) = false BooleanUtils.toBooleanDefaultIfNull(null, true)          = true 
if (bool == null) {
    return valueIfNull;
return bool.booleanValue() ? true : false;
BooleantoBooleanObject(final int val)
Method to convert int to Boolean object
return val != 0 ? Boolean.TRUE : Boolean.FALSE;
BooleantoBooleanObject(final String str)
to Boolean Object
if (str == "true") {
    return Boolean.TRUE;
if (str == null) {
    return null;
switch (str.length()) {
case 1: {
...
BooleantoBooleanObject(int value, int trueValue, int falseValue, int nullValue)

Converts an int to a Boolean specifying the conversion values.

NOTE: This returns null and will throw a NullPointerException if autoboxed to a boolean.

if (value == trueValue) {
    return Boolean.TRUE;
if (value == falseValue) {
    return Boolean.FALSE;
if (value == nullValue) {
    return null;
...
BooleantoBooleanObject(int value, int trueValue, int falseValue, int nullValue)
to Boolean Object
if (value == trueValue) {
    return Boolean.TRUE;
} else if (value == falseValue) {
    return Boolean.FALSE;
} else if (value == nullValue) {
    return null;
throw new IllegalArgumentException("The Integer did not match any specified value");
...
BooleantoBooleanObject(String str)
to Boolean Object
return str != null ? Boolean.valueOf(str) : null;