Here you can find the source of arrayConcat(String[] first, String second)
Parameter | Description |
---|---|
first | the first array to concatenate |
second | the array to add at the end of the first array |
public static final String[] arrayConcat(String[] first, String second)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w . ja v a2 s . c o m * Returns a new array adding the second array at the end of first array. * It answers null if the first and second are null. * If the first array is null or if it is empty, then a new array is created with second. * If the second array is null, then the first array is returned. * <br> * <br> * For example: * <ol> * <li><pre> * first = null * second = "a" * => result = {"a"} * </pre> * <li><pre> * first = {"a"} * second = null * => result = {"a"} * </pre> * </li> * <li><pre> * first = {"a"} * second = {"b"} * => result = {"a", "b"} * </pre> * </li> * </ol> * * @param first the first array to concatenate * @param second the array to add at the end of the first array * @return a new array adding the second array at the end of first array, or null if the two arrays are null. */ public static final String[] arrayConcat(String[] first, String second) { if (second == null) return first; if (first == null) return new String[] { second }; int length = first.length; if (first.length == 0) { return new String[] { second }; } String[] result = new String[length + 1]; System.arraycopy(first, 0, result, 0, length); result[length] = second; return result; } }