Differences between | and || operators in Java


| is a bitwise operator and compares each operands bitwise.

It is a binary OR Operator and copies a bit to the result it exists in either operands.

Assume integer variable A holds 60 and variable B holds 13 then  

(A | B) will give 61 which is 0011 1101.

Whereas || is a logical OR operator and operates on boolean operands. If both the operands are false, then the condition becomes false otherwise it is true. Assume boolean variable A holds true and variable B holds false then (A && B) is true.

| is to be used during bitwise operations and || is useful during logical operations.

Updated on: 30-Jul-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements