Class BooleanUtils
- java.lang.Object
- 
- org.apache.commons.lang3.BooleanUtils
 
- 
 public class BooleanUtils extends java.lang.ObjectOperations on boolean primitives and Boolean objects. This class tries to handle nullinput gracefully. An exception will not be thrown for anullinput. Each method documents its behavior in more detail.#ThreadSafe# - Since:
- 2.0
 
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringFALSEThe false String"false".static java.lang.StringNOThe no String"no".static java.lang.StringOFFThe off String"off".static java.lang.StringONThe on String"on".static java.lang.StringTRUEThe true String"true".static java.lang.StringYESThe yes String"yes".
 - 
Constructor SummaryConstructors Constructor Description BooleanUtils()BooleanUtilsinstances should NOT be constructed in standard programming.
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanand(boolean... array)Performs an 'and' operation on a set of booleans.static java.lang.Booleanand(java.lang.Boolean... array)Performs an 'and' operation on an array of Booleans.static java.lang.Boolean[]booleanValues()Returns a new array of possible values (like an enum would).static intcompare(boolean x, boolean y)Compares twobooleanvalues.static booleanisFalse(java.lang.Boolean bool)Checks if aBooleanvalue isfalse, handlingnullby returningfalse.static booleanisNotFalse(java.lang.Boolean bool)Checks if aBooleanvalue is notfalse, handlingnullby returningtrue.static booleanisNotTrue(java.lang.Boolean bool)Checks if aBooleanvalue is nottrue, handlingnullby returningtrue.static booleanisTrue(java.lang.Boolean bool)Checks if aBooleanvalue istrue, handlingnullby returningfalse.static java.lang.Booleannegate(java.lang.Boolean bool)Negates the specified boolean.static booleanor(boolean... array)Performs an 'or' operation on a set of booleans.static java.lang.Booleanor(java.lang.Boolean... array)Performs an 'or' operation on an array of Booleans.static boolean[]primitiveValues()Returns a new array of possible values (like an enum would).static booleantoBoolean(int value)Converts an int to a boolean using the convention thatzeroisfalse, everything else istrue.static booleantoBoolean(int value, int trueValue, int falseValue)Converts an int to a boolean specifying the conversion values.static booleantoBoolean(java.lang.Boolean bool)Converts a Boolean to a boolean handlingnullby returningfalse.static booleantoBoolean(java.lang.Integer value, java.lang.Integer trueValue, java.lang.Integer falseValue)Converts an Integer to a boolean specifying the conversion values.static booleantoBoolean(java.lang.String str)Converts a String to a boolean (optimised for performance).static booleantoBoolean(java.lang.String str, java.lang.String trueString, java.lang.String falseString)Converts a String to a Boolean throwing an exception if no match found.static booleantoBooleanDefaultIfNull(java.lang.Boolean bool, boolean valueIfNull)Converts a Boolean to a boolean handlingnull.static java.lang.BooleantoBooleanObject(int value)Converts an int to a Boolean using the convention thatzeroisfalse, everything else istrue.static java.lang.BooleantoBooleanObject(int value, int trueValue, int falseValue, int nullValue)Converts an int to a Boolean specifying the conversion values.static java.lang.BooleantoBooleanObject(java.lang.Integer value)Converts an Integer to a Boolean using the convention thatzeroisfalse, every other numeric value istrue.static java.lang.BooleantoBooleanObject(java.lang.Integer value, java.lang.Integer trueValue, java.lang.Integer falseValue, java.lang.Integer nullValue)Converts an Integer to a Boolean specifying the conversion values.static java.lang.BooleantoBooleanObject(java.lang.String str)Converts a String to a Boolean.static java.lang.BooleantoBooleanObject(java.lang.String str, java.lang.String trueString, java.lang.String falseString, java.lang.String nullString)Converts a String to a Boolean throwing an exception if no match.static inttoInteger(boolean bool)Converts a boolean to an int using the convention thattrueis1andfalseis0.static inttoInteger(boolean bool, int trueValue, int falseValue)Converts a boolean to an int specifying the conversion values.static inttoInteger(java.lang.Boolean bool, int trueValue, int falseValue, int nullValue)Converts a Boolean to an int specifying the conversion values.static java.lang.IntegertoIntegerObject(boolean bool)Converts a boolean to an Integer using the convention thattrueis1andfalseis0.static java.lang.IntegertoIntegerObject(boolean bool, java.lang.Integer trueValue, java.lang.Integer falseValue)Converts a boolean to an Integer specifying the conversion values.static java.lang.IntegertoIntegerObject(java.lang.Boolean bool)Converts a Boolean to a Integer using the convention thatzeroisfalse.static java.lang.IntegertoIntegerObject(java.lang.Boolean bool, java.lang.Integer trueValue, java.lang.Integer falseValue, java.lang.Integer nullValue)Converts a Boolean to an Integer specifying the conversion values.static java.lang.StringtoString(boolean bool, java.lang.String trueString, java.lang.String falseString)Converts a boolean to a String returning one of the input Strings.static java.lang.StringtoString(java.lang.Boolean bool, java.lang.String trueString, java.lang.String falseString, java.lang.String nullString)Converts a Boolean to a String returning one of the input Strings.static java.lang.StringtoStringOnOff(boolean bool)Converts a boolean to a String returning'on'or'off'.static java.lang.StringtoStringOnOff(java.lang.Boolean bool)Converts a Boolean to a String returning'on','off', ornull.static java.lang.StringtoStringTrueFalse(boolean bool)Converts a boolean to a String returning'true'or'false'.static java.lang.StringtoStringTrueFalse(java.lang.Boolean bool)Converts a Boolean to a String returning'true','false', ornull.static java.lang.StringtoStringYesNo(boolean bool)Converts a boolean to a String returning'yes'or'no'.static java.lang.StringtoStringYesNo(java.lang.Boolean bool)Converts a Boolean to a String returning'yes','no', ornull.static booleanxor(boolean... array)Performs an xor on a set of booleans.static java.lang.Booleanxor(java.lang.Boolean... array)Performs an xor on an array of Booleans.
 
- 
- 
- 
Field Detail- 
FALSEpublic static final java.lang.String FALSE The false String"false".- Since:
- 3.12.0
- See Also:
- Constant Field Values
 
 - 
NOpublic static final java.lang.String NO The no String"no".- Since:
- 3.12.0
- See Also:
- Constant Field Values
 
 - 
OFFpublic static final java.lang.String OFF The off String"off".- Since:
- 3.12.0
- See Also:
- Constant Field Values
 
 - 
ONpublic static final java.lang.String ON The on String"on".- Since:
- 3.12.0
- See Also:
- Constant Field Values
 
 - 
TRUEpublic static final java.lang.String TRUE The true String"true".- Since:
- 3.12.0
- See Also:
- Constant Field Values
 
 - 
YESpublic static final java.lang.String YES The yes String"yes".- Since:
- 3.12.0
- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
andpublic static boolean and(boolean... array) Performs an 'and' operation on a set of booleans. BooleanUtils.and(true, true) = true BooleanUtils.and(false, false) = false BooleanUtils.and(true, false) = false BooleanUtils.and(true, true, false) = false BooleanUtils.and(true, true, true) = true - Parameters:
- array- an array of- booleans
- Returns:
- the result of the logical 'and' operation. That is falseif any of the parameters isfalseandtrueotherwise.
- Throws:
- java.lang.NullPointerException- if- arrayis- null
- java.lang.IllegalArgumentException- if- arrayis empty.
- Since:
- 3.0.1
 
 - 
andpublic static java.lang.Boolean and(java.lang.Boolean... array) Performs an 'and' operation on an array of Booleans. BooleanUtils.and(Boolean.TRUE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.and(Boolean.FALSE, Boolean.FALSE) = Boolean.FALSE BooleanUtils.and(Boolean.TRUE, Boolean.FALSE) = Boolean.FALSE BooleanUtils.and(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.and(Boolean.FALSE, Boolean.FALSE, Boolean.TRUE) = Boolean.FALSE BooleanUtils.and(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE) = Boolean.FALSE - Parameters:
- array- an array of- Booleans
- Returns:
- the result of the logical 'and' operation. That is falseif any of the parameters isfalseandtrueotherwise.
- Throws:
- java.lang.NullPointerException- if- arrayis- null
- java.lang.IllegalArgumentException- if- arrayis empty.
- java.lang.IllegalArgumentException- if- arraycontains a- null
- Since:
- 3.0.1
 
 - 
booleanValuespublic static java.lang.Boolean[] booleanValues() Returns a new array of possible values (like an enum would).- Returns:
- a new array of possible values (like an enum would).
- Since:
- 3.12.0
 
 - 
comparepublic static int compare(boolean x, boolean y)Compares two booleanvalues. This is the same functionality as provided in Java 7.- Parameters:
- x- the first- booleanto compare
- y- the second- booleanto compare
- Returns:
- the value 0ifx == y; a value less than0if!x && y; and a value greater than0ifx && !y
- Since:
- 3.4
 
 - 
isFalsepublic static boolean isFalse(java.lang.Boolean bool) Checks if a Booleanvalue isfalse, handlingnullby returningfalse.BooleanUtils.isFalse(Boolean.TRUE) = false BooleanUtils.isFalse(Boolean.FALSE) = true BooleanUtils.isFalse(null) = false - Parameters:
- bool- the boolean to check, null returns- false
- Returns:
- trueonly if the input is non-- nulland- false
- Since:
- 2.1
 
 - 
isNotFalsepublic static boolean isNotFalse(java.lang.Boolean bool) Checks if a Booleanvalue is notfalse, handlingnullby returningtrue.BooleanUtils.isNotFalse(Boolean.TRUE) = true BooleanUtils.isNotFalse(Boolean.FALSE) = false BooleanUtils.isNotFalse(null) = true - Parameters:
- bool- the boolean to check, null returns- true
- Returns:
- trueif the input is- nullor- true
- Since:
- 2.3
 
 - 
isNotTruepublic static boolean isNotTrue(java.lang.Boolean bool) Checks if a Booleanvalue is nottrue, handlingnullby returningtrue.BooleanUtils.isNotTrue(Boolean.TRUE) = false BooleanUtils.isNotTrue(Boolean.FALSE) = true BooleanUtils.isNotTrue(null) = true - Parameters:
- bool- the boolean to check, null returns- true
- Returns:
- trueif the input is null or false
- Since:
- 2.3
 
 - 
isTruepublic static boolean isTrue(java.lang.Boolean bool) Checks if a Booleanvalue istrue, handlingnullby returningfalse.BooleanUtils.isTrue(Boolean.TRUE) = true BooleanUtils.isTrue(Boolean.FALSE) = false BooleanUtils.isTrue(null) = false - Parameters:
- bool- the boolean to check,- nullreturns- false
- Returns:
- trueonly if the input is non-null and true
- Since:
- 2.1
 
 - 
negatepublic static java.lang.Boolean negate(java.lang.Boolean bool) Negates the specified boolean. If nullis passed in,nullwill be returned.NOTE: This returns nulland will throw aNullPointerExceptionif unboxed to a boolean.BooleanUtils.negate(Boolean.TRUE) = Boolean.FALSE; BooleanUtils.negate(Boolean.FALSE) = Boolean.TRUE; BooleanUtils.negate(null) = null; - Parameters:
- bool- the Boolean to negate, may be null
- Returns:
- the negated Boolean, or nullifnullinput
 
 - 
orpublic static boolean or(boolean... array) Performs an 'or' operation on a set of booleans. BooleanUtils.or(true, true) = true BooleanUtils.or(false, false) = false BooleanUtils.or(true, false) = true BooleanUtils.or(true, true, false) = true BooleanUtils.or(true, true, true) = true BooleanUtils.or(false, false, false) = false - Parameters:
- array- an array of- booleans
- Returns:
- trueif any of the arguments is- true, and it returns- falseotherwise.
- Throws:
- java.lang.NullPointerException- if- arrayis- null
- java.lang.IllegalArgumentException- if- arrayis empty.
- Since:
- 3.0.1
 
 - 
orpublic static java.lang.Boolean or(java.lang.Boolean... array) Performs an 'or' operation on an array of Booleans. BooleanUtils.or(Boolean.TRUE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.FALSE, Boolean.FALSE) = Boolean.FALSE BooleanUtils.or(Boolean.TRUE, Boolean.FALSE) = Boolean.TRUE BooleanUtils.or(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.FALSE, Boolean.FALSE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE) = Boolean.FALSE - Parameters:
- array- an array of- Booleans
- Returns:
- trueif any of the arguments is- true, and it returns- falseotherwise.
- Throws:
- java.lang.NullPointerException- if- arrayis- null
- java.lang.IllegalArgumentException- if- arrayis empty.
- java.lang.IllegalArgumentException- if- arraycontains a- null
- Since:
- 3.0.1
 
 - 
primitiveValuespublic static boolean[] primitiveValues() Returns a new array of possible values (like an enum would).- Returns:
- a new array of possible values (like an enum would).
- Since:
- 3.12.0
 
 - 
toBooleanpublic static boolean toBoolean(java.lang.Boolean bool) Converts a Boolean to a boolean handling nullby returningfalse.BooleanUtils.toBoolean(Boolean.TRUE) = true BooleanUtils.toBoolean(Boolean.FALSE) = false BooleanUtils.toBoolean(null) = false - Parameters:
- bool- the boolean to convert
- Returns:
- trueor- false,- nullreturns- false
 
 - 
toBooleanpublic static boolean toBoolean(int value) Converts an int to a boolean using the convention that zeroisfalse, everything else istrue.BooleanUtils.toBoolean(0) = false BooleanUtils.toBoolean(1) = true BooleanUtils.toBoolean(2) = true - Parameters:
- value- the int to convert
- Returns:
- trueif non-zero,- falseif zero
 
 - 
toBooleanpublic static boolean toBoolean(int value, int trueValue, int falseValue)Converts an int to a boolean specifying the conversion values. If the trueValueandfalseValueare the same number then the return value will betruein casevaluematches it.BooleanUtils.toBoolean(0, 1, 0) = false BooleanUtils.toBoolean(1, 1, 0) = true BooleanUtils.toBoolean(1, 1, 1) = true BooleanUtils.toBoolean(2, 1, 2) = false BooleanUtils.toBoolean(2, 2, 0) = true - Parameters:
- value- the- Integerto convert
- trueValue- the value to match for- true
- falseValue- the value to match for- false
- Returns:
- trueor- false
- Throws:
- java.lang.IllegalArgumentException- if- valuedoes not match neither- trueValueno- falseValue
 
 - 
toBooleanpublic static boolean toBoolean(java.lang.Integer value, java.lang.Integer trueValue, java.lang.Integer falseValue)Converts an Integer to a boolean specifying the conversion values. BooleanUtils.toBoolean(Integer.valueOf(0), Integer.valueOf(1), Integer.valueOf(0)) = false BooleanUtils.toBoolean(Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(0)) = true BooleanUtils.toBoolean(Integer.valueOf(2), Integer.valueOf(1), Integer.valueOf(2)) = false BooleanUtils.toBoolean(Integer.valueOf(2), Integer.valueOf(2), Integer.valueOf(0)) = true BooleanUtils.toBoolean(null, null, Integer.valueOf(0)) = true - Parameters:
- value- the Integer to convert
- trueValue- the value to match for- true, may be- null
- falseValue- the value to match for- false, may be- null
- Returns:
- trueor- false
- Throws:
- java.lang.IllegalArgumentException- if no match
 
 - 
toBooleanpublic static boolean toBoolean(java.lang.String str) Converts a String to a boolean (optimised for performance). 'true','on','y','t'or'yes'(case insensitive) will returntrue. Otherwise,falseis returned.This method performs 4 times faster (JDK1.4) than Boolean.valueOf(String). However, this method accepts 'on' and 'yes', 't', 'y' as true values.BooleanUtils.toBoolean(null) = false BooleanUtils.toBoolean("true") = true BooleanUtils.toBoolean("TRUE") = true BooleanUtils.toBoolean("tRUe") = true BooleanUtils.toBoolean("on") = true BooleanUtils.toBoolean("yes") = true BooleanUtils.toBoolean("false") = false BooleanUtils.toBoolean("x gti") = false BooleanUtils.toBoolean("y") = true BooleanUtils.toBoolean("n") = false BooleanUtils.toBoolean("t") = true BooleanUtils.toBoolean("f") = false- Parameters:
- str- the String to check
- Returns:
- the boolean value of the string, falseif no match or the String is null
 
 - 
toBooleanpublic static boolean toBoolean(java.lang.String str, java.lang.String trueString, java.lang.String falseString)Converts a String to a Boolean throwing an exception if no match found. BooleanUtils.toBoolean("true", "true", "false") = true BooleanUtils.toBoolean("false", "true", "false") = false- Parameters:
- str- the String to check
- trueString- the String to match for- true(case sensitive), may be- null
- falseString- the String to match for- false(case sensitive), may be- null
- Returns:
- the boolean value of the string
- Throws:
- java.lang.IllegalArgumentException- if the String doesn't match
 
 - 
toBooleanDefaultIfNullpublic static boolean toBooleanDefaultIfNull(java.lang.Boolean bool, boolean valueIfNull)Converts a Boolean to a boolean handling null.BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, false) = true BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, true) = true BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, true) = false BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, false) = false BooleanUtils.toBooleanDefaultIfNull(null, true) = true BooleanUtils.toBooleanDefaultIfNull(null, false) = false - Parameters:
- bool- the boolean object to convert to primitive
- valueIfNull- the boolean value to return if the parameter- boolis- null
- Returns:
- trueor- false
 
 - 
toBooleanObjectpublic static java.lang.Boolean toBooleanObject(int value) Converts an int to a Boolean using the convention that zeroisfalse, everything else istrue.BooleanUtils.toBoolean(0) = Boolean.FALSE BooleanUtils.toBoolean(1) = Boolean.TRUE BooleanUtils.toBoolean(2) = Boolean.TRUE - Parameters:
- value- the int to convert
- Returns:
- Boolean.TRUE if non-zero, Boolean.FALSE if zero,
  nullifnull
 
 - 
toBooleanObjectpublic static java.lang.Boolean toBooleanObject(int value, int trueValue, int falseValue, int nullValue)Converts an int to a Boolean specifying the conversion values. NOTE: This method may return nulland may throw aNullPointerExceptionif unboxed to aboolean.The checks are done first for the trueValue, then for thefalseValueand finally for thenullValue.BooleanUtils.toBooleanObject(0, 0, 2, 3) = Boolean.TRUE BooleanUtils.toBooleanObject(0, 0, 0, 3) = Boolean.TRUE BooleanUtils.toBooleanObject(0, 0, 0, 0) = Boolean.TRUE BooleanUtils.toBooleanObject(2, 1, 2, 3) = Boolean.FALSE BooleanUtils.toBooleanObject(2, 1, 2, 2) = Boolean.FALSE BooleanUtils.toBooleanObject(3, 1, 2, 3) = null - Parameters:
- value- the Integer to convert
- trueValue- the value to match for- true
- falseValue- the value to match for- false
- nullValue- the value to to match for- null
- Returns:
- Boolean.TRUE, Boolean.FALSE, or null
- Throws:
- java.lang.IllegalArgumentException- if no match
 
 - 
toBooleanObjectpublic static java.lang.Boolean toBooleanObject(java.lang.Integer value) Converts an Integer to a Boolean using the convention that zeroisfalse, every other numeric value istrue.nullwill be converted tonull.NOTE: This method may return nulland may throw aNullPointerExceptionif unboxed to aboolean.BooleanUtils.toBooleanObject(Integer.valueOf(0)) = Boolean.FALSE BooleanUtils.toBooleanObject(Integer.valueOf(1)) = Boolean.TRUE BooleanUtils.toBooleanObject(Integer.valueOf(null)) = null - Parameters:
- value- the Integer to convert
- Returns:
- Boolean.TRUE if non-zero, Boolean.FALSE if zero,
  nullifnullinput
 
 - 
toBooleanObjectpublic static java.lang.Boolean toBooleanObject(java.lang.Integer value, java.lang.Integer trueValue, java.lang.Integer falseValue, java.lang.Integer nullValue)Converts an Integer to a Boolean specifying the conversion values. NOTE: This method may return nulland may throw aNullPointerExceptionif unboxed to aboolean.The checks are done first for the trueValue, then for thefalseValueand finally for thenullValue.BooleanUtils.toBooleanObject(Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(2), Integer.valueOf(3)) = Boolean.TRUE BooleanUtils.toBooleanObject(Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(3)) = Boolean.TRUE BooleanUtils.toBooleanObject(Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0)) = Boolean.TRUE BooleanUtils.toBooleanObject(Integer.valueOf(2), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)) = Boolean.FALSE BooleanUtils.toBooleanObject(Integer.valueOf(2), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(2)) = Boolean.FALSE BooleanUtils.toBooleanObject(Integer.valueOf(3), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)) = null - Parameters:
- value- the Integer to convert
- trueValue- the value to match for- true, may be- null
- falseValue- the value to match for- false, may be- null
- nullValue- the value to to match for- null, may be- null
- Returns:
- Boolean.TRUE, Boolean.FALSE, or null
- Throws:
- java.lang.IllegalArgumentException- if no match
 
 - 
toBooleanObjectpublic static java.lang.Boolean toBooleanObject(java.lang.String str) Converts a String to a Boolean. 'true','on','y','t','yes'or'1'(case insensitive) will returntrue.'false','off','n','f','no'or'0'(case insensitive) will returnfalse. Otherwise,nullis returned.NOTE: This method may return nulland may throw aNullPointerExceptionif unboxed to aboolean.// N.B. case is not significant BooleanUtils.toBooleanObject(null) = null BooleanUtils.toBooleanObject("true") = Boolean.TRUE BooleanUtils.toBooleanObject("T") = Boolean.TRUE // i.e. T[RUE] BooleanUtils.toBooleanObject("false") = Boolean.FALSE BooleanUtils.toBooleanObject("f") = Boolean.FALSE // i.e. f[alse] BooleanUtils.toBooleanObject("No") = Boolean.FALSE BooleanUtils.toBooleanObject("n") = Boolean.FALSE // i.e. n[o] BooleanUtils.toBooleanObject("on") = Boolean.TRUE BooleanUtils.toBooleanObject("ON") = Boolean.TRUE BooleanUtils.toBooleanObject("off") = Boolean.FALSE BooleanUtils.toBooleanObject("oFf") = Boolean.FALSE BooleanUtils.toBooleanObject("yes") = Boolean.TRUE BooleanUtils.toBooleanObject("Y") = Boolean.TRUE // i.e. Y[ES] BooleanUtils.toBooleanObject("1") = Boolean.TRUE BooleanUtils.toBooleanObject("0") = Boolean.FALSE BooleanUtils.toBooleanObject("blue") = null BooleanUtils.toBooleanObject("true ") = null // trailing space (too long) BooleanUtils.toBooleanObject("ono") = null // does not match on or no- Parameters:
- str- the String to check; upper and lower case are treated as the same
- Returns:
- the Boolean value of the string, nullif no match ornullinput
 
 - 
toBooleanObjectpublic static java.lang.Boolean toBooleanObject(java.lang.String str, java.lang.String trueString, java.lang.String falseString, java.lang.String nullString)Converts a String to a Boolean throwing an exception if no match. NOTE: This method may return nulland may throw aNullPointerExceptionif unboxed to aboolean.BooleanUtils.toBooleanObject("true", "true", "false", "null") = Boolean.TRUE BooleanUtils.toBooleanObject(null, null, "false", "null") = Boolean.TRUE BooleanUtils.toBooleanObject(null, null, null, "null") = Boolean.TRUE BooleanUtils.toBooleanObject(null, null, null, null) = Boolean.TRUE BooleanUtils.toBooleanObject("false", "true", "false", "null") = Boolean.FALSE BooleanUtils.toBooleanObject("false", "true", "false", "false") = Boolean.FALSE BooleanUtils.toBooleanObject(null, "true", null, "false") = Boolean.FALSE BooleanUtils.toBooleanObject(null, "true", null, null) = Boolean.FALSE BooleanUtils.toBooleanObject("null", "true", "false", "null") = null- Parameters:
- str- the String to check
- trueString- the String to match for- true(case sensitive), may be- null
- falseString- the String to match for- false(case sensitive), may be- null
- nullString- the String to match for- null(case sensitive), may be- null
- Returns:
- the Boolean value of the string, nullif either the String matchesnullStringor ifnullinput andnullStringisnull
- Throws:
- java.lang.IllegalArgumentException- if the String doesn't match
 
 - 
toIntegerpublic static int toInteger(boolean bool) Converts a boolean to an int using the convention that trueis1andfalseis0.BooleanUtils.toInteger(true) = 1 BooleanUtils.toInteger(false) = 0 - Parameters:
- bool- the boolean to convert
- Returns:
- one if true, zero iffalse
 
 - 
toIntegerpublic static int toInteger(boolean bool, int trueValue, int falseValue)Converts a boolean to an int specifying the conversion values. BooleanUtils.toInteger(true, 1, 0) = 1 BooleanUtils.toInteger(false, 1, 0) = 0 - Parameters:
- bool- the to convert
- trueValue- the value to return if- true
- falseValue- the value to return if- false
- Returns:
- the appropriate value
 
 - 
toIntegerpublic static int toInteger(java.lang.Boolean bool, int trueValue, int falseValue, int nullValue)Converts a Boolean to an int specifying the conversion values. BooleanUtils.toInteger(Boolean.TRUE, 1, 0, 2) = 1 BooleanUtils.toInteger(Boolean.FALSE, 1, 0, 2) = 0 BooleanUtils.toInteger(null, 1, 0, 2) = 2 - Parameters:
- bool- the Boolean to convert
- trueValue- the value to return if- true
- falseValue- the value to return if- false
- nullValue- the value to return if- null
- Returns:
- the appropriate value
 
 - 
toIntegerObjectpublic static java.lang.Integer toIntegerObject(boolean bool) Converts a boolean to an Integer using the convention that trueis1andfalseis0.BooleanUtils.toIntegerObject(true) = Integer.valueOf(1) BooleanUtils.toIntegerObject(false) = Integer.valueOf(0) - Parameters:
- bool- the boolean to convert
- Returns:
- one if true, zero iffalse
 
 - 
toIntegerObjectpublic static java.lang.Integer toIntegerObject(boolean bool, java.lang.Integer trueValue, java.lang.Integer falseValue)Converts a boolean to an Integer specifying the conversion values. BooleanUtils.toIntegerObject(true, Integer.valueOf(1), Integer.valueOf(0)) = Integer.valueOf(1) BooleanUtils.toIntegerObject(false, Integer.valueOf(1), Integer.valueOf(0)) = Integer.valueOf(0) - Parameters:
- bool- the to convert
- trueValue- the value to return if- true, may be- null
- falseValue- the value to return if- false, may be- null
- Returns:
- the appropriate value
 
 - 
toIntegerObjectpublic static java.lang.Integer toIntegerObject(java.lang.Boolean bool) Converts a Boolean to a Integer using the convention that zeroisfalse.nullwill be converted tonull.BooleanUtils.toIntegerObject(Boolean.TRUE) = Integer.valueOf(1) BooleanUtils.toIntegerObject(Boolean.FALSE) = Integer.valueOf(0) - Parameters:
- bool- the Boolean to convert
- Returns:
- one if Boolean.TRUE, zero if Boolean.FALSE, nullifnull
 
 - 
toIntegerObjectpublic static java.lang.Integer toIntegerObject(java.lang.Boolean bool, java.lang.Integer trueValue, java.lang.Integer falseValue, java.lang.Integer nullValue)Converts a Boolean to an Integer specifying the conversion values. BooleanUtils.toIntegerObject(Boolean.TRUE, Integer.valueOf(1), Integer.valueOf(0), Integer.valueOf(2)) = Integer.valueOf(1) BooleanUtils.toIntegerObject(Boolean.FALSE, Integer.valueOf(1), Integer.valueOf(0), Integer.valueOf(2)) = Integer.valueOf(0) BooleanUtils.toIntegerObject(null, Integer.valueOf(1), Integer.valueOf(0), Integer.valueOf(2)) = Integer.valueOf(2) - Parameters:
- bool- the Boolean to convert
- trueValue- the value to return if- true, may be- null
- falseValue- the value to return if- false, may be- null
- nullValue- the value to return if- null, may be- null
- Returns:
- the appropriate value
 
 - 
toStringpublic static java.lang.String toString(boolean bool, java.lang.String trueString, java.lang.String falseString)Converts a boolean to a String returning one of the input Strings. BooleanUtils.toString(true, "true", "false") = "true" BooleanUtils.toString(false, "true", "false") = "false" - Parameters:
- bool- the Boolean to check
- trueString- the String to return if- true, may be- null
- falseString- the String to return if- false, may be- null
- Returns:
- one of the two input Strings
 
 - 
toStringpublic static java.lang.String toString(java.lang.Boolean bool, java.lang.String trueString, java.lang.String falseString, java.lang.String nullString)Converts a Boolean to a String returning one of the input Strings. BooleanUtils.toString(Boolean.TRUE, "true", "false", null) = "true" BooleanUtils.toString(Boolean.FALSE, "true", "false", null) = "false" BooleanUtils.toString(null, "true", "false", null) = null; - Parameters:
- bool- the Boolean to check
- trueString- the String to return if- true, may be- null
- falseString- the String to return if- false, may be- null
- nullString- the String to return if- null, may be- null
- Returns:
- one of the three input Strings
 
 - 
toStringOnOffpublic static java.lang.String toStringOnOff(boolean bool) Converts a boolean to a String returning 'on'or'off'.BooleanUtils.toStringOnOff(true) = "on" BooleanUtils.toStringOnOff(false) = "off" - Parameters:
- bool- the Boolean to check
- Returns:
- 'on',- 'off', or- null
 
 - 
toStringOnOffpublic static java.lang.String toStringOnOff(java.lang.Boolean bool) Converts a Boolean to a String returning 'on','off', ornull.BooleanUtils.toStringOnOff(Boolean.TRUE) = "on" BooleanUtils.toStringOnOff(Boolean.FALSE) = "off" BooleanUtils.toStringOnOff(null) = null; - Parameters:
- bool- the Boolean to check
- Returns:
- 'on',- 'off', or- null
 
 - 
toStringTrueFalsepublic static java.lang.String toStringTrueFalse(boolean bool) Converts a boolean to a String returning 'true'or'false'.BooleanUtils.toStringTrueFalse(true) = "true" BooleanUtils.toStringTrueFalse(false) = "false" - Parameters:
- bool- the Boolean to check
- Returns:
- 'true',- 'false', or- null
 
 - 
toStringTrueFalsepublic static java.lang.String toStringTrueFalse(java.lang.Boolean bool) Converts a Boolean to a String returning 'true','false', ornull.BooleanUtils.toStringTrueFalse(Boolean.TRUE) = "true" BooleanUtils.toStringTrueFalse(Boolean.FALSE) = "false" BooleanUtils.toStringTrueFalse(null) = null; - Parameters:
- bool- the Boolean to check
- Returns:
- 'true',- 'false', or- null
 
 - 
toStringYesNopublic static java.lang.String toStringYesNo(boolean bool) Converts a boolean to a String returning 'yes'or'no'.BooleanUtils.toStringYesNo(true) = "yes" BooleanUtils.toStringYesNo(false) = "no" - Parameters:
- bool- the Boolean to check
- Returns:
- 'yes',- 'no', or- null
 
 - 
toStringYesNopublic static java.lang.String toStringYesNo(java.lang.Boolean bool) Converts a Boolean to a String returning 'yes','no', ornull.BooleanUtils.toStringYesNo(Boolean.TRUE) = "yes" BooleanUtils.toStringYesNo(Boolean.FALSE) = "no" BooleanUtils.toStringYesNo(null) = null; - Parameters:
- bool- the Boolean to check
- Returns:
- 'yes',- 'no', or- null
 
 - 
xorpublic static boolean xor(boolean... array) Performs an xor on a set of booleans. BooleanUtils.xor(true, true) = false BooleanUtils.xor(false, false) = false BooleanUtils.xor(true, false) = true - Parameters:
- array- an array of- booleans
- Returns:
- the result of the xor operations
- Throws:
- java.lang.NullPointerException- if- arrayis- null
- java.lang.IllegalArgumentException- if- arrayis empty.
 
 - 
xorpublic static java.lang.Boolean xor(java.lang.Boolean... array) Performs an xor on an array of Booleans. BooleanUtils.xor(new Boolean[] { Boolean.TRUE, Boolean.TRUE }) = Boolean.FALSE BooleanUtils.xor(new Boolean[] { Boolean.FALSE, Boolean.FALSE }) = Boolean.FALSE BooleanUtils.xor(new Boolean[] { Boolean.TRUE, Boolean.FALSE }) = Boolean.TRUE BooleanUtils.xor(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE) = Boolean.TRUE- Parameters:
- array- an array of- Booleans
- Returns:
- the result of the xor operations
- Throws:
- java.lang.NullPointerException- if- arrayis- null
- java.lang.IllegalArgumentException- if- arrayis empty.
- java.lang.IllegalArgumentException- if- arraycontains a- null
 
 
- 
 
-