Java Array Merge merge2TablesWithoutDup(String[] t1, String[] t2)

Here you can find the source of merge2TablesWithoutDup(String[] t1, String[] t2)

Description

Source https://stackoverflow.com/questions/16520046/how-to-merge-two-arraylists-without-duplicates Added by JG 2017

License

Open Source License

Parameter

Parameter Description
t1 first table
t2 second table

Return

merged table of string without duplicates from two tables

Declaration

public static String[] merge2TablesWithoutDup(String[] t1, String[] t2) 

Method Source Code

//package com.java2s;
/*//from   w  w  w . j a  va  2 s .  c om
*  Armadillo Workflow Platform v1.0
*  A simple pipeline system for phylogenetic analysis
*
*  Copyright (C) 2009-2011  Etienne Lord, Mickael Leclercq
*
*  This program 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 3 of the License, or
*  (at your option) any later version.
*
*  This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;

public class Main {
    /**
     * Source https://stackoverflow.com/questions/16520046/how-to-merge-two-arraylists-without-duplicates
     * Added by JG 2017
     * @param t1 first table
     * @param t2 second table
     * @return merged table of string without duplicates from two tables
     */
    public static String[] merge2TablesWithoutDup(String[] t1, String[] t2) {
        List<String> sL1 = new ArrayList<String>(Arrays.asList(t1));
        for (int i = 0; i < t2.length; i++) {
            if (!sL1.contains(t2[i]))
                sL1.add(t2[i]);
        }
        String[] f = sL1.toArray(new String[0]);
        return f;
    }

    public static Integer[] merge2TablesWithoutDup(Integer[] t1, Integer[] t2) {
        List<Integer> sL1 = new ArrayList<Integer>(Arrays.asList(t1));
        for (int i = 0; i < t2.length; i++) {
            if (!sL1.contains(t2[i]))
                sL1.add(t2[i]);
        }
        Integer[] f = sL1.toArray(new Integer[0]);
        return f;
    }
}

Related

  1. merge(T[] first, T[] second)
  2. merge(T[] first, T[] second)
  3. merge(T[] left, T... right)
  4. merge(T[]... arrays)
  5. merge(T[]... many)
  6. mergeAndOrderArray(int[] arrA, int[] arrB)
  7. mergeArgs(String[] args)
  8. mergeArray(byte[] arr1, byte[] arr2)
  9. mergeArray(final Object[] dest, final Object[]... arrays)