java.lang.Boolean logicalAnd(boolean a, boolean b)

Description

The logicalAnd(boolean a, boolean b) method of Boolean class returns the result of applying the logical AND operator to the specified boolean operands. For reference here is the truth table in performing a logical and operator.

First Value Second Value Result
true true true
true false false
false true false
false false false

As a general rule, in performing a logical and operator, the only time that it will result true is when both value are true.

Method Syntax

public static boolean logicalAnd(boolean a, boolean b)

Method Argument

Data Type Parameter Description
boolean a the first operand
boolean b the second operand

Method Returns

The logicalAnd(boolean a, boolean b) method of Boolean class returns the logical AND of a and b.

Discussion

The logiocalAnd method of Boolean class is one of the newest addition as of Java 1.8. This is to take into consideration the instances wherein we have to perform AND operation be that be a logical circuit or situation. So instead of relying on conditional statements, we now have an underlying methods that handle the logical AND operation which shortens and simplifying the development of computer programs.

Java Boolean logicalAnd(boolean a, boolean b) Example

Below is a simple java example on the usage of logicalAnd() method of Boolean class.

To fully demonstrate the behaviour of logicalAnd() method, the program above is designed in such a way that user can enter two boolean values and then the result of logicalAnd() method is displayed based on the two user input. On this way, the user can experiment on different values as input.

Sample Output

Below is the sample output when you run the above example.

java Boolean logicalAnd() example output