What is the best way to guard against null in a for loop in Java?
This seems ugly :
if (someList != null) { for (Object object : someList) {
It's already 2017, and you can now use Apache Commons Collections4
The usage:
for(Object obj : ListUtils.emptyIfNull(list1)){ // Do your stuff }
You can do the same null-safe check to other Collection classes with CollectionUtils.emptyIfNull.
CollectionUtils.emptyIfNull