copy List of element to another List - Android java.util

Android examples for java.util:List Element

Description

copy List of element to another List

Demo Code


//package com.java2s;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Main {
    public static <T> List<T> copy(List<T> list) {
        ArrayList copy = new ArrayList();
        if (isEmpty((Collection) list)) {
            return copy;
        } else {/*from w  w  w.  j  a v a2s  .  com*/
            Iterator i$ = list.iterator();

            while (i$.hasNext()) {
                Object t = i$.next();
                copy.add(t);
            }

            return copy;
        }
    }

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

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

Related Tutorials