add All Values from Map to Collection - Android java.util

Android examples for java.util:Map

Description

add All Values from Map 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 addAllValues(Collection<T> c, Map<?, T> map) {
        c.addAll(map.values());/*from   w w w  .j  a v  a2 s .  co m*/
    }

    public static <T> void addAll(Collection<T> c, T[] array) {
        if (isEmpty(array)) {
            return;
        }
        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