What is the difference between null!=variable
and variable!=null
Which method is perfect to use?
if ((null != value1) || (null != value2) || (null != value3)) {
.......
.......
.......
}
or
if ((value1 != null) || (value2 != null) || (value3 != null)) {
.......
.......
.......
}
Please suggest the best one and the logical change between these?
No difference.
But people quite often write "abc".equals(foo), instead of foo.equals("abc"), to avoid null point exception.
Nothing is different.
I prefer value != null
for purely readability reasons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With