Java List Union union(final List list1, final List list2)

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

Description

Returns a new list containing the second list appended to the first list.

License

Open Source License

Parameter

Parameter Description
list1 the first list
list2 the second list

Exception

Parameter Description
NullPointerException if either list is null

Return

a new list containing the union of those lists

Declaration

public static List union(final List list1, final List list2) 

Method Source Code


//package com.java2s;
/*//  ww w  . j a  v a 2  s  .  c o  m
 * Copyright (c) 2007-2016 AREasy Runtime
 *
 * This library, AREasy Runtime and API for BMC Remedy AR System, is free software ("Licensed Software");
 * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT,
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 */

import java.util.*;

public class Main {
    /**
     * Returns a new list containing the second list appended to the
     * first list.  The {@link List#addAll(Collection)} operation is
     * used to append the two given lists into a new list.
     *
     * @param list1 the first list
     * @param list2 the second list
     * @return a new list containing the union of those lists
     * @throws NullPointerException if either list is null
     */
    public static List union(final List list1, final List list2) {
        final ArrayList result = new ArrayList(list1);

        result.addAll(list2);

        return result;
    }
}

Related

  1. shallowUnionCol(Collection> values)
  2. union(final char[]... list)
  3. union(final List list1, final List list2)
  4. union(final List list1, final List list2)
  5. union(final List list1, final List list2)
  6. union(final List... lists)