import java.util.List; /** * 对象判空 * */ public class EmptyUtil { public boolean isEmpty(Object object) { if (object == null) { return true; } if (object instanceof List) { return ((List) object).size() == 0; } if (object instanceof String) { return ((String) object).trim().equals(""); } return false; } }
调用时提前引入封装好的工具类,引用isEmpty方法传入参数即可