JAVA中判断Array、List、Map、Set是否空的方法

来源:互联网 发布:游戏里被广为人知的梗 编辑:程序博客网 时间:2024/06/04 01:14

在JAVA中经常用到判断参数是否为空,每次都判断会写很多重复代码,所以有时间整理了一下。这个类可以直接拿来用。

其中主要包括判断List是否为空、判断Map是否为空、判断Set是否为空、判断Array'是否为空。

public final class EmptyUtil
{
private EmptyUtil()
{
}

        public static boolean isEmptyList(List<?> list)

{
return (null == list || list.size() == 0);
}


public static boolean isNotEmptyList(List<?> list)
{
return !isEmptyList(list);
}


public static boolean isEmptyMap(Map<?, ?> map)
{
return (null == map || map.size() == 0);
}


public static boolean isNotEmptyMap(Map<?, ?> map)
{
return !isEmptyMap(map);
}


public static boolean isEmptySet(Set<?> set)
{
return (null == set || set.size() == 0);
}


public static boolean isNotEmptySet(Set<?> set)
{
return !isEmptySet(set);
}


public static boolean isEmptyArray(Object[] objs)
{
return (null == objs || objs.length == 0);
}


public static boolean isNotEmptyArray(Object[] objs)
{
return !isEmptyArray(objs);

}

}

原创粉丝点击