+ 3
What is the difference between operands | and || in java?
3 ответов
+ 17
|| is logical OR. It gives True if at least one of the conditions is true.
example:
(2<5 || 5==4 || 5%2==0)
= true || false || false
= true
| is biwise OR. It converts the operands to equivalent binary numbers and checks bit by bit. At least one occurrence of 1 gives 1.
example:
(5 | 3 | 0)
= 101 | 011 | 000
= 111
= 7
+ 15
Here's a sample code :) Just trying out the new feature 😊
https://code.sololearn.com/cQDnUvsn2gU1/?ref=app
+ 1
As far as i know || operator compares the expression to the left with the expression to the right and so does the | operator also.
Difference is when the left side of the || operator is true then the right wird will not be compared but the | operator does.