Java tutorial
//package com.java2s; /* * File: $RCSfile$ * * Copyright (c) 2005 Wincor Nixdorf International GmbH, * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany * All Rights Reserved. * * This software is the confidential and proprietary information * of Wincor Nixdorf ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered * into with Wincor Nixdorf. */ import java.util.List; import java.util.Iterator; public class Main { /** * Safety add element included in source collection to target collection * if target has already had element that is included in source collection, * it doesn't add element to target * * @param src source collection * @param target target collection */ public static void safetyMergeCollection(List src, List target) { for (Iterator it = src.iterator(); it.hasNext();) { Object data = it.next(); if (!target.contains(data)) { target.add(data); } } } }