Java List Uniqne Item uniqueListInsert(List list1, List list2)

Here you can find the source of uniqueListInsert(List list1, List list2)

Description

Inserts the elements of a List into another List making sure not to duplicate entries in the resulting List

License

Open Source License

Parameter

Parameter Description
list1 The List containing unique entries
list2 The second List to be inserted into the first List

Return

The updated list1 with new unique entries

Declaration

private static List<String> uniqueListInsert(List<String> list1, List<String> list2) 

Method Source Code

//package com.java2s;
/*  Copyright (C) 2003-2015 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General public static License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version./*w ww .  j a  v  a  2 s .  c  om*/
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General public static License for more details.
    
You should have received a copy of the GNU General public static License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import java.util.List;

public class Main {
    /**
     * Inserts the elements of a List into another List making sure not to duplicate entries in the resulting List
     *
     * @param list1 The List containing unique entries
     * @param list2 The second List to be inserted into the first List
     * @return The updated list1 with new unique entries
     */
    private static List<String> uniqueListInsert(List<String> list1, List<String> list2) {
        if (list2 != null) {
            for (String fromList2 : list2) {
                if (!list1.contains(fromList2) && (!"#".equals(fromList2))) {
                    list1.add(fromList2);
                }
            }
        }
        return list1;
    }
}

Related

  1. unique(List array)
  2. unique(List entities)
  3. unique(List list)
  4. uniqueList(Collection

    list)

  5. uniqueList(List list)
  6. uniqueMacTest(List macs, String attempt)