非空验证工具类

空扰寡人 提交于 2019-11-29 09:39:49
//验证为空
	public static <T> boolean isEmpty(T obj){
		return !isNotEmpty(obj);
	}

	//验证非空
	public static <T> boolean isNotEmpty(T obj){
        if(obj != null){
            if(obj instanceof String){
                //字符串
                return  String.valueOf(obj).trim().length() > 0;
            }else if(obj instanceof ArrayList){
                //集合
                return ((List) obj).size() > 0;
            }else if(obj instanceof HashMap){
                //Map
                return !((Map) obj).isEmpty();
            }else if(obj instanceof HashSet){
                //Set
                return ((Set) obj).size() > 0;
            }else if(obj instanceof byte[]){
                //byte[]
                return ((byte[]) obj).length > 0;
            }else if(obj instanceof short[]){
                //short[]
                return ((short[]) obj).length > 0;
            }else if(obj instanceof int[]){
                //int[]
                return ((int[]) obj).length > 0;
            }else if(obj instanceof long[]){
                //long[]
                return ((long[]) obj).length > 0;
            }else if(obj instanceof String[]){
                //String[]
                return ((String[]) obj).length > 0;
            }else if(obj instanceof Object[]){
                //Object[]
                return ((Object[]) obj).length > 0;
            }else if(obj instanceof Object){
                System.out.println("Object");
                return !"".equals(obj) && !"null".equals(obj);
            }
        }
		return false;
	}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!