What is Boolean.logicalAnd in Java?

Overview

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 values

A 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

Method signature

public static boolean logicalAnd(boolean a, boolean b)

Parameters:

boolean a: first operand
boolean b: second operand

Returns:

This method returns the logical AND of the two operands.

Code

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));
}
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources