No, java.util.List.isEmpty() doesn't check if a list is null.
If you are using the Spring framework you can use the CollectionUtils class to check if a list is empty or not. It also takes care of the null references. Following is the code snippet from Spring framework's CollectionUtils class.
public static boolean isEmpty(Collection<?> collection) {
return (collection == null || collection.isEmpty());
}
Even if you are not using Spring, you can go on and tweak this code and add it in your AppUtil class like below.
public class AppUtil {
...
public static boolean isEmpty(Collection<?> collection) {
return (collection == null || collection.isEmpty());
}
...
}
then use the method anywhere like so
List<Car> myCars = ...
if(AppUtil.isEmpty(myCars)) {
System.out.println("Work hard to get some");
}