Trusted answers to developer questions

What is Boolean.logicalOr in Java?

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

Overview

The logicalOr method is a static method of the Boolean class in Java. The method computes the logical OR operation on two Boolean operands/values.

The logical OR operator is represented as || in Java. This method was introduced in Java 8.

OR operation on Boolean values

A Boolean data type can take 2 values, i.e. true and false. The result of the logical OR 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 true
false true true
false false false

Method Signature

public static boolean logicalOr(boolean a, boolean b)

Parameters

boolean a - first operand.
boolean b - second operand.

Return values

Logical OR of the two operands.

Code

public class Main {
public static void main(String[] args) {
System.out.println("true || true = " + Boolean.logicalOr(true, true));
System.out.println("true || false = " + Boolean.logicalOr(true, false));
System.out.println("false || true = " + Boolean.logicalOr(false, true));
System.out.println("false || false = " + Boolean.logicalOr(false, false));
}
}

RELATED TAGS

java
boolean
Did you find this helpful?