Difference Between | (Single Pipe) and ||
The difference is that the | (single pipe) is bitwise or operator and when it can also be used in condition design.
for eg.
class CheckCondition{
public static boolean checkMe(int x)
{
System.out.println("checked");
if(x>10)
return true;
else
return false;
}
public static void main(String[] args)
{
int a=2,b=32,c=4;
if( checkMe(2) | checkMe(2) | checkMe(4)){
System.out.println("====");
}
if(checkMe(2) || checkMe(2) || checkMe(4)){
System.out.println("====");
}
}
}
In above code snippet " | " will check every part of condition while " || " will check in sequence starting from first. If any condition in sequence is found to be true then || stops further checking. so || is more efficient in conditional statements.
Written by safy
Related protips
1 Response
its really helpful for me
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Difference between single pipe and double pipe
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#