add All array Element to Collection - Android java.util

Android examples for java.util:Collection Element

Description

add All array Element to Collection

Demo Code


//package com.book2s;

import java.util.Arrays;
import java.util.Collection;

import java.util.Enumeration;

import java.util.Map;

public class Main {
    public static <T> void addAll(Collection<T> c, T[] array) {
        if (isEmpty(array)) {
            return;
        }/*from   ww  w.  j  a v a  2 s .c om*/
        c.addAll(Arrays.asList(array));
    }

    public static <T> void addAll(Collection<T> c,
            Enumeration<T> enumeration) {
        while (enumeration.hasMoreElements()) {
            c.add(enumeration.nextElement());
        }
    }

    public static boolean isEmpty(Collection<?> c) {
        return c == null || c.isEmpty();
    }

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

    @SafeVarargs
    public static <T> boolean isEmpty(T... array) {
        return array == null || array.length == 0;
    }
}

Related Tutorials