Boolean.logicalOr() method in Java

logicalOr() method performs the logical OR operation between two boolean values. It’s a static method and was introduced in Java 1.8. This post will discuss the logicalOr() method of the Boolean wrapper class in detail.

  • Method declaration – public static boolean logicalOr(boolean a, boolean b)
  • What does it do? logicalOr() method takes two boolean arguments and performs the logical OR operation.
  • What does it return? It will return the final value after performing the logical OR operation.
Internal implementation of the logicalOr() method
    public static boolean logicalOr(boolean a, boolean b) {
        return a || b;
    }

Below are the combinations that can be passed in the logicalOr() method and the corresponding value it will return.

Code Example
public class Codekru {

	public static void main(String[] args) {

		System.out.println("value 1: " + Boolean.logicalOr(true, true));
		System.out.println("value 2: " + Boolean.logicalOr(true, false));
		System.out.println("value 3: " + Boolean.logicalOr(false, true));
		System.out.println("value 4: " + Boolean.logicalOr(false, false));
	}
}

Output –

value 1: true
value 2: true
value 3: true
value 4: false
Time Complexity of the logicalOr() method

As logicalOr() method only performs the OR operation between two boolean values. So, the time complexity of the logicalOr() method is O(1).

Please visit this link to learn more about the Boolean wrapper class of java and its other functions or methods.

We hope that you have liked the article. If you have any doubts or concerns, please feel free to write us in the comments or mail us at admin@codekru.com.

Liked the article? Share this on

Leave a Comment

Your email address will not be published. Required fields are marked *