Difference between & and && in Java With Example

  • '&' is bitwise. & evaluates both sides of the operation.
  • '&&' is logical.&& evaluates the left side of the operation, if it's true, it continues and evaluates the right side.This is known as shortcircuiting and may be considered an optimisation. This is especially useful in guarding against nullness.
if( x != null && x.equals("JavaStuff.in") {
  then do something with x...
}

Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email