How to check a Long for null in java

BrownTownCoder picture BrownTownCoder · Oct 29, 2014 · Viewed 198.9k times · Source

How do I check a Long value for null in Java?

Will this work?

if ( longValue == null) { return blah; }

Answer

brso05 picture brso05 · Oct 29, 2014

Primitive data types cannot be null. Only Object data types can be null.

int, long, etc... can't be null.

If you use Long (wrapper class for long) then you can check for null's:

Long longValue = null;

if(longValue == null)