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) {
Use, CollectionUtils.isEmpty(Collection coll) method which is Null-safe check if the specified collection is empty.
CollectionUtils.isEmpty(Collection coll)
for this import org.apache.commons.collections.CollectionUtils.
import org.apache.commons.collections.CollectionUtils
Maven dependency
org.apache.commons commons-collections4 4.0