Java Array Concatenate concatUniq(String[] part1, String[] part2)

Here you can find the source of concatUniq(String[] part1, String[] part2)

Description

Concat two arrays of Strings, and prevent that duplicate Strings are present in result part2 is appended to part1

License

Open Source License

Declaration

public static String[] concatUniq(String[] part1, String[] part2) 

Method Source Code


//package com.java2s;

import java.util.ArrayList;

public class Main {
    /**//from   ww  w  .  jav  a2  s. c o  m
     * Concat two arrays of Strings, and prevent that duplicate
     * Strings are present in result
     * part2 is appended to part1
     */
    public static String[] concatUniq(String[] part1, String[] part2) {
        ArrayList nlist = new ArrayList();

        for (int i = 0; i < part1.length; i++) {
            if (!nlist.contains(part1[i]))
                nlist.add(part1[i]);
        }

        for (int i = 0; i < part2.length; i++) {
            if (!nlist.contains(part2[i]))
                nlist.add(part2[i]);
        }

        return (String[]) nlist.toArray(new String[0]);
    }
}

Related

  1. concatenateArrays(T[] first, T[]... rest)
  2. concatenateStrings(Object[] strings, String glueString)
  3. concatIntArrays(final int[] l1, final int[] l2)
  4. concatStrings(String[] strs, String delimiter)
  5. concatTwoStringArray(String[] first, String[] second)
  6. concatUnique(String[] a, String[] b)