Java tutorial
//package com.java2s; import java.util.Collection; public class Main { /** Copy elements from src to dest. * * @param src - Collection containing data to be copied. * @param dest - Collection to have the data copied to. * @param clearDestination - whether to clear all contents from destination prior to copying. */ public static <T> void copyElements(Collection<? extends T> src, Collection<? super T> dest, boolean clearDestination) { if (clearDestination) { dest.clear(); } for (T t : src) { dest.add(t); } } }