If I have a rarely used collection in some class which may be instantiated many times, I may sometimes resort to the following \"idiom\" in order to save unnecessary object crea
You can create a utility class with static methods, like:
public class ListUtil {
/**
* Checks if {@link List} is null or empty.
*
* @param the generic type
* @param list the list
* @return true, if is null or empty
*/
public static boolean isNullOrEmpty(List list) {
return list == null || list.size() == 0;
}
/**
* Checks if {@link List} is not null and empty.
*
* @param the generic type
* @param list the list
* @return true, if is not null and empty
*/
public static boolean isNotNullAndEmpty(List list) {
return list != null && list.size() != 0;
}
}