Skip to content

Instantly share code, notes, and snippets.

@unrelentingfox
Created July 27, 2018 20:22
Show Gist options
  • Save unrelentingfox/844e4bc7da0eb15be0aba2b3889bc167 to your computer and use it in GitHub Desktop.
Save unrelentingfox/844e4bc7da0eb15be0aba2b3889bc167 to your computer and use it in GitHub Desktop.
Useful java safe comparison helper functions
private static boolean safeEquals(Integer first, Integer second) {
return (first == null && second == null) || (first != null && first.equals(second));
}
private static boolean safeContains(String str, String substr) {
return str != null && str.contains(substr);
}
private static <K> List<K> safe(List<K> list) {
return list != null ? list : Collections.EMPTY_LIST;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment