我是靠谱客的博主 现实白昼,这篇文章主要介绍集合对象工具类CollectionUtil,现在分享给大家,希望可以做个参考。


package com.example.util;

import java.util.Collection;
import java.util.Map;

/**
 * 集合对象工具类
 * 
 * @author wangzengyang@gmail.com 2012-11-12
 * 
 */
public class CollectionUtil {

    /**
     * 获取集合大小
     * 
     * @param collection
     *            集合
     * @return
     */
    public static int size(Collection<?> collection) {
        return isEmpty(collection) ? 0 : collection.size();
    }

    /**
     * 检查集合元素是否存在
     * 
     * @param collection
     *            集合
     * @return
     */
    public static boolean isAvailable(Collection<?> collection, int index) {
        if (isEmpty(collection))
            return false;
        return index >= 0 && index < collection.size();

    }

    /**
     * 检查集合元素是否为空
     * 
     * @param collection
     *            集合
     * @return
     */
    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();

    }

    /**
     * 检查数组元素是否为空
     * 
     * @param array
     *            数组
     * @return
     */
    public static boolean isEmpty(Object[] array) {
        return array == null || array.length == 0;

    }

    /**
     * 检查Map元素是否为空
     * 
     * @param map
     *            Map
     * @return
     */
    public static boolean isEmpty(Map<?, ?> map) {
        return map == null || map.isEmpty();

    }
}


转载于:https://blog.51cto.com/tiantiankaixin/1869441

最后

以上就是现实白昼最近收集整理的关于集合对象工具类CollectionUtil的全部内容,更多相关集合对象工具类CollectionUtil内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(113)

评论列表共有 0 条评论

立即
投稿
返回
顶部