Java Array Concatenate concatTwoStringArray(String[] first, String[] second)

Here you can find the source of concatTwoStringArray(String[] first, String[] second)

Description

Merge Two String arrays together into one.

License

Open Source License

Parameter

Parameter Description
first first String[]
second second String[]

Return

Merged String[]

Declaration

static public String[] concatTwoStringArray(String[] first,
        String[] second) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *  Copyright (c) 2014, 2016 IBM Corporation.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class Main {
    /**//  w w  w.j a  v  a2  s  .co  m
     * Merge Two String arrays together into one.
     * @param first first String[]
     * @param second second String[]
     * @return Merged String[]
     */
    static public String[] concatTwoStringArray(String[] first,
            String[] second) {
        List<String> both = new ArrayList<String>(first.length
                + second.length);
        Collections.addAll(both, first);
        Collections.addAll(both, second);
        return both.toArray(new String[both.size()]);
    }
}

Related

  1. concatenateArray(Object[] srcOne, Object[] srcTwo)
  2. concatenateArrays(T[] first, T[]... rest)
  3. concatenateStrings(Object[] strings, String glueString)
  4. concatIntArrays(final int[] l1, final int[] l2)
  5. concatStrings(String[] strs, String delimiter)
  6. concatUniq(String[] part1, String[] part2)
  7. concatUnique(String[] a, String[] b)