Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
boolean
and
communitycreator

What is Boolean.logicalAnd in Java?

abhilash

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));
    }
}

RELATED TAGS

java
boolean
and
communitycreator
RELATED COURSES

View all Courses

Keep Exploring