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?
constant != xwas often recommended in languages like C. This was called Yoda Conditions and helped to avoid cases likex = constantasconstant = xwould raise a compiler error. (However, in Java the only case when this matters is when doing a comparison with abooleanwhich should be avoided anyway.)null != xorx != null. Pick one and be consistent (which also means following the form already used in a project).