The logicalAnd
method is a static method of the Boolean
class in Java. The method computes the logical AND
operation on two boolean operands/values. The logical AND
operator is represented as &&
in Java. This method was introduced in Java 8.
AND
operation on boolean valuesA boolean data type takes two values, i.e., true
and false
. The result of a logical AND
operation between the different combinations of the two boolean data types is as follows:
First Operand | Second Operand | First Operand && Second Operand |
---|---|---|
true | true | true |
true | false | false |
false | true | false |
false | false | false |
public static boolean logicalAnd(boolean a, boolean b)
boolean a
: first operand
boolean b
: second operand
This method returns the logical AND
of the two operands.
public class Main { public static void main(String[] args) { System.out.println("true && true = " + Boolean.logicalAnd(true, true)); System.out.println("true && false = " + Boolean.logicalAnd(true, false)); System.out.println("false && true = " + Boolean.logicalAnd(false, true)); System.out.println("false && false = " + Boolean.logicalAnd(false, false)); } }
RELATED TAGS
CONTRIBUTOR
View all Courses