Here you can find the source of mergeArrays(String[] array, String[] newEntries)
Parameter | Description |
---|---|
array | the first array. |
newEntries | the second array. |
public static String[] mergeArrays(String[] array, String[] newEntries)
//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); } }