Skip to content

Instantly share code, notes, and snippets.

@ankushs92
Created February 28, 2016 05:27
Show Gist options
  • Save ankushs92/69300c47c6cc1428986e to your computer and use it in GitHub Desktop.
Save ankushs92/69300c47c6cc1428986e to your computer and use it in GitHub Desktop.
Java : Check if a Number object has value null or 0.
public class NumberUtils{
public boolean isNullOrZero(final Number number){
return number == null ||
(
number instanceof Integer ? number.intValue() == 0 :
number instanceof Long ? number.longValue() == 0 :
number instanceof Double ? number.doubleValue() == 0 :
number instanceof Short ? number.shortValue() == 0 :
number.floatValue() == 0
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment