The isTrue
static method of the BooleanUtils
class can be used to check if the passed Boolean value is equal to true
.
public static boolean isTrue(Boolean bool);
The isTrue
method takes a Boolean
object as an argument.
isTrue
returns true
if the passed argument is equal to true
. Otherwise, the method returns false
.
If we pass null
, then isTrue
returns false
.
BooleanUtils
BooleanUtils
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-lang
package, refer to the Maven Repository.
Case | Result |
BooleanUtils.isTrue(Boolean.TRUE) | true |
BooleanUtils.isTrue(Boolean.FALSE) | false |
BooleanUtils.isTrue(null) | false |
In the below code, we use the isTrue
method as follows:
import org.apache.commons.lang3.BooleanUtils;class IsTrueExample {public static void main( String args[] ) {System.out.println("BooleanUtils.isTrue(Boolean.TRUE) => " + BooleanUtils.isTrue(Boolean.TRUE)); // trueSystem.out.println("BooleanUtils.isTrue(Boolean.FALSE) => " + BooleanUtils.isTrue(Boolean.FALSE)); // falseSystem.out.println("BooleanUtils.isTrue(null) => " + BooleanUtils.isTrue(null)); // false}}
In the above code:
BooleanUtils
class.import org.apache.commons.lang3.BooleanUtils;
isTrue
method to check if the passed argument is true
.BooleanUtils.isTrue(Boolean.TRUE); // true
BooleanUtils.isTrue(Boolean.FALSE); // false
BooleanUtils.isTrue(null); // false