Java Array Merge mergeArrays(String[] array, String[] newEntries)

Here you can find the source of mergeArrays(String[] array, String[] newEntries)

Description

Returns the union of the two arrays specified.

License

Open Source License

Parameter

Parameter Description
array the first array.
newEntries the second array.

Return

the union of the two arrays specified.

Declaration

public static String[] mergeArrays(String[] array, String[] newEntries) 

Method Source Code


//package com.java2s;
/*==========================================================================*\
 |  $Id: ProjectOptionsUtil.java,v 1.2 2009/09/13 12:59:29 aallowat Exp $
 |*-------------------------------------------------------------------------*|
 |  Copyright (C) 2006-2009 Virginia Tech 
 |
 |   This file is part of Web-CAT Eclipse Plugins.
 |
 |   Web-CAT is free software; you can redistribute it and/or modify
 |   it under the terms of the GNU General Public License as published by
 |   the Free Software Foundation; either version 2 of the License, or
 |   (at your option) any later version.
 |
 |   Web-CAT 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 License for more details.
 |
 |   You should have received a copy of the GNU General Public License
 |   along with Web-CAT; if not, see <http://www.gnu.org/licenses/>.
\*==========================================================================*/

import java.util.ArrayList;

public class Main {
    /**//from w  w  w .ja  va  2 s  . com
     * Returns the union of the two arrays specified. There will be no
     * duplicates in the resultant array.
     * 
     * @param array
     *            the first array.
     * @param newEntries
     *            the second array.
     * @return the union of the two arrays specified.
     */
    public static String[] mergeArrays(String[] array, String[] newEntries) {
        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < array.length; i++)
            list.add(array[i]);

        for (int i = 0; i < newEntries.length; i++)
            if (!list.contains(newEntries[i]))
                list.add(newEntries[i]);

        String[] newArray = new String[list.size()];
        return list.toArray(newArray);
    }
}

Related

  1. mergeArrays(long[] alldistances, long[] currentUserDistances)
  2. mergeArrays(Object[] arr1, Object[] arr2, Object[] destinationArray)
  3. mergeArrays(Object[] first, Object[] second)
  4. mergeArrays(String[] a, String[] b)
  5. mergeArrays(String[] a1, String[] a2)
  6. mergeArrays(String[] data1, String[] data2)
  7. mergeArrays(String[] inputArray1, String[] inputArray2)
  8. mergeArrays(T[] items, T[]... added)
  9. mergeArrays(T[] lhs, T[] rhs)