Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between null!=variable and variable!=null

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?

like image 238
JayKay Avatar asked Sep 17 '14 05:09

JayKay


2 Answers

No difference.

But people quite often write "abc".equals(foo), instead of foo.equals("abc"), to avoid null point exception.

like image 54
Peter Pei Guo Avatar answered Sep 22 '22 06:09

Peter Pei Guo


Nothing is different.

I prefer value != null for purely readability reasons.

like image 44
Thihara Avatar answered Sep 23 '22 06:09

Thihara