com.penglecode.common.util.CollectionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons Show documentation
Show all versions of commons Show documentation
commons is a little java tool to make your development easier in your work.
The newest version!
package com.penglecode.common.util;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
/**
* 集合类型的工具类
*
* @author pengpeng
* @date 2014年7月19日 下午3:38:21
* @version 1.0
*/
public class CollectionUtils {
/**
* 判断Collection>集合是否为空
*
* @param collection
* @return
*/
public static boolean isEmpty(Collection> collection){
return collection == null || collection.isEmpty();
}
/**
* 判断Map,?>集合是否为空
*
* @param map
* @return
*/
public static boolean isEmpty(Map,?> map){
return map == null || map.isEmpty();
}
/**
* 判断Collection>集合中是否含有null元素
*
* @param collection
* @return
*/
public static boolean containsNull(Collection> collection){
if(!isEmpty(collection)){
for(Object obj : collection){
if(obj == null){
return true;
}
}
}
return false;
}
/**
* 过滤Collection>集合中的null元素
*
* @param collection
*/
public static void filterNull(Collection> collection){
if(!isEmpty(collection)){
for(Iterator> it = collection.iterator(); it.hasNext();){
if(it.next() == null){
it.remove();
}
}
}
}
}