Here you can find the source of mergeArrays(String[] a, String[] b)
Parameter | Description |
---|---|
a | A string array |
b | A string array |
a
and b
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String[] mergeArrays(String[] a, String[] b)
//package com.java2s; //License from project: LGPL import java.util.*; public class Main { /**//from ww w .j av a 2s . c o m * Create the union of two string arrays. * Duplicate entries are removed. * * @param a A string array * @param b A string array * @return The union of <code>a</code> and <code>b</code> */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static String[] mergeArrays(String[] a, String[] b) { if (a == null) { return b; } if (b == null) { return a; } // found all names in a which are not in b Vector v = new Vector(); for (int i = 0; i < a.length; i++) { int j = 0; boolean found = false; do { if (a[i].equalsIgnoreCase(b[j])) { found = true; } else { j++; } } while (!found && j < b.length); if (!found) { v.add(a[i]); } } String[] c = new String[b.length + v.size()]; Enumeration aEnum = v.elements(); int i = 0; while (aEnum.hasMoreElements()) { c[i++] = (String) aEnum.nextElement(); } for (int j = 0; j < b.length; j++) { c[i++] = b[j]; } return c; } }