The toStringTrueFalse method of the BooleanUtils class converts a boolean value to its equivalent. For instance, toStringTrueFalse will return the string "true" if the passed argument is true, and the string "false" in case the boolean value is false. If the argument is null, then the method returns null.
public static String toStringTrueFalse(Boolean bool);
bool: the Boolean object to be converted to the string equivalent."true": If the argument is Boolean.TRUE."false": If the argument is Boolean.FALSE.null: If the argument is null.BooleanUtilsBooleanUtils is defined in the Apache Commons Lang package. Apache Commons Lang can be added to the Maven project by adding the following dependency to the pom.xml file.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
For other versions of the
commons-langpackage, refer to the Maven Repository.
You can import BooleanUtils as follows:
import org.apache.commons.lang3.BooleanUtils;
Case | Result |
BooleanUtils.toStringTrueFalse(Boolean.TRUE) | "true" |
BooleanUtils.toStringTrueFalse(Boolean.FALSE) | "fallse" |
BooleanUtils.toStringTrueFalse(null) | null |
In the code below, we use the toStringTrueFalse method as follows.
import org.apache.commons.lang3.BooleanUtils;class ToStringTrueFalseExample {public static void main( String args[] ) {System.out.println("BooleanUtils.toStringTrueFalse(Boolean.TRUE) => " + BooleanUtils.toStringTrueFalse(Boolean.TRUE)); // "true"System.out.println("BooleanUtils.toStringTrueFalse(Boolean.FALSE) => " + BooleanUtils.toStringTrueFalse(Boolean.FALSE)); // "false"System.out.println("BooleanUtils.toStringTrueFalse(null) => " + BooleanUtils.toStringTrueFalse(null)); // null}}
"BooleanUtils.toStringTrueFalse(Boolean.TRUE) => true"
"BooleanUtils.toStringTrueFalse(Boolean.FALSE) => false"
"BooleanUtils.toStringTrueFalse(null) => null"
In the code above:
BooleanUtils class.import org.apache.commons.lang3.BooleanUtils;
toStringTrueFalse method to get the “true” or “false” string based on the passed argument.