|| is a type of Logical Operator and is read as “OR OR” or “Logical OR“. This operator is used to perform “logical OR” operation, i.e. the function similar to OR gate in digital electronics.
One thing to keep in mind is the second condition is not evaluated if the first one is false, i.e. it has a short-circuiting effect. Used extensively to test for several conditions for making a decision.
Syntax:
Condition1 || Condition2 // returns true if one of the conditions is true.
Below is an example to demonstrate || operator:
Example:
// Java program to illustrate // logical OR operator import java.util.*; public class operators { public static void main(String[] args) { char ch = 'a'; // check if character is alphabet or digit // using || operator if (ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122) System.out.println( ch + " is an alphabet."); else if (ch >= 48 && ch <= 57) System.out.println( ch + " is a digit."); else System.out.println( ch + " is a special character."); } } |
a is an alphabet.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- new operator in Java
- && operator in Java with Examples
- & Operator in Java with Examples
- Difference between concat() and + operator in Java
- Java Ternary Operator with Examples
- Java Unary Operator with Examples
- Java Assignment Operator with Examples
- Double colon (::) operator in Java
- new operator vs newInstance() method in Java
- Java Ternary Operator Puzzle
- Equality (==) operator in Java with Examples
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
- instanceof operator vs isInstance() method in Java
- Diamond operator for Anonymous Inner Class with Examples in Java
- Ternary operator vs Null coalescing operator in PHP
- 'AND' vs '&&' as operator in PHP
- set operator= in C++ STL
- What is the difference between the | and || or operator in php?
- Double not (!!) operator in PHP
- unordered_set == operator in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


