CollectionUtils 判断空 和 join分隔符

package cn.trinea.android.common.util;

import java.util.Collection;

import android.text.TextUtils;

/**
 * CollectionUtils
 * 
 * @author Trinea 2012-7-22
 */
public class CollectionUtils {

    /** default join separator **/
    public static final CharSequence DEFAULT_JOIN_SEPARATOR = ",";

    private CollectionUtils() {
        throw new AssertionError();
    }

    /**
     * is null or its size is 0
     * 
     * 
     * isEmpty(null)   =   true;
     * isEmpty({})     =   true;
     * isEmpty({1})    =   false;
     * 
* * @param <V> * @param c * @return if collection is null or its size is 0, return true, else return false. */ public static boolean isEmpty(Collection c) { return (c == null || c.size() == 0); } /** * join collection to string, separator is {@link #DEFAULT_JOIN_SEPARATOR} * *
     * join(null)      =   "";
     * join({})        =   "";
     * join({a,b})     =   "a,b";
     * 
* * @param collection * @return join collection to string, separator is {@link #DEFAULT_JOIN_SEPARATOR}. if collection is empty, return * "" */ public static String join(Iterable collection) { return collection == null ? "" : TextUtils.join(DEFAULT_JOIN_SEPARATOR, collection); } }

你可能感兴趣的:(安卓工具)