Java tutorial
//package com.java2s; //License from project: Apache License import java.util.Collection; public class Main { /** * Return if the iterable is null or contains no elements. * * @param iterable * @return */ public static boolean isNullOrEmpty(Iterable<?> iterable) { if (iterable == null) { return true; } if (iterable instanceof Collection) { return ((Collection<?>) iterable).isEmpty(); } return !iterable.iterator().hasNext(); } }