Java List Merge safetyMergeCollection(List src, List target)

Here you can find the source of safetyMergeCollection(List src, List target)

Description

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

License

Open Source License

Parameter

Parameter Description
src source collection
target target collection

Declaration

public static void safetyMergeCollection(List src, List target) 

Method Source Code


//package com.java2s;
/*/*from w  w  w . j av a  2 s  .co  m*/
 * 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);
            }
        }
    }
}

Related

  1. mergeString(List strs)
  2. mergeTimeStrings(List strs)
  3. mergeTo(List target, List source)
  4. mergeToList(Object src, Object... args)
  5. mergeUniqElems(List src, List dest)

  6. HOME | Copyright © www.java2s.com 2016