Java.lang Package Classes

Java Boolean - logicalAnd() Method



The java.lang.Boolean.logicalAnd() method returns the result of applying the logical AND operator to the specified boolean operands.

Syntax

public static boolean logicalAnd(boolean a,
                                 boolean b)

Parameters

a Specify the first operand.
b Specify the second operand.

Return Value

Returns the logical AND of a and b.

Exception

NA.

Example:

In the example below, the java.lang.Boolean.logicalAnd() method returns the result of applying the logical AND operator to the given boolean operands.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating boolean values
    boolean b1 = true;
    boolean b2 = false;

    //printing the result of applying AND operator  
    System.out.println("b1 AND b1: " + Boolean.logicalAnd(b1, b1)); 
    System.out.println("b2 AND b2: " + Boolean.logicalAnd(b2, b2));  
    System.out.println("b1 AND b2: " + Boolean.logicalAnd(b1, b2));   
  }
}

The output of the above code will be:

b1 AND b1: true
b2 AND b2: false
b1 AND b2: false

❮ Java.lang - Boolean