&& (AND) and || (OR) in Java IF statements
Posted
by Azimuth
on Stack Overflow
See other posts from Stack Overflow
or by Azimuth
Published on 2009-11-25T09:50:12Z
Indexed on
2010/05/09
5:18 UTC
Read the original article
Hit count: 144
java
|if-statement
My question might be very basic but still I think it worths to ask. I have the following code:
if(!partialHits.get(req_nr).containsKey(z) || partialHits.get(req_nr).get(z) < tmpmap.get(z)){
partialHits.get(z).put(z, tmpmap.get(z));
}
where partialHits
is a HashMap. What will happen if the first statement is true? Will Java still check the second statement? Because in order the first statement to be true, the HashMap should not contain the given key, so if the second statement is checked, I will get NullPointerException
.
So in simple words, if we have the following code
if(a && b)
if(a || b)
would Java check b
if a
is false in the first case and if a
is true in the second case?
© Stack Overflow or respective owner