Here you can find the source of mergeArrays(String[] inputArray1, String[] inputArray2)
Parameter | Description |
---|---|
inputArray1 | Input Array 1 that needs to be merged |
inputArray2 | Input Array 2 that needs to be merged |
public static String[] mergeArrays(String[] inputArray1, String[] inputArray2)
//package com.java2s; public class Main { /**//from w ww. j a v a2 s . c o m * This method merges 2 input string arrays and returns the merged array as output * * @param inputArray1 Input Array 1 that needs to be merged * @param inputArray2 Input Array 2 that needs to be merged * @return Returns merged Array that contains all elements of inputArray1 followed by elements of inputArray2 * <p/> * <b>Example:</b> The following are the input array * <p/> * inputArray1 contains elements ("a","b","c") * <p/> * inputArray2 contains element ("b","e") * <p/> * then the output array contains elements * <p/> * ("a","b","c","b","e") */ public static String[] mergeArrays(String[] inputArray1, String[] inputArray2) { String[] outputArray = new String[inputArray1.length + inputArray2.length]; /** * Copy first array to outputArray */ for (int i = 0; i < inputArray1.length; i++) { outputArray[i] = inputArray1[i]; } /** * Copy second array to outputArray */ int outputArrayLength = inputArray1.length; for (int i = 0; i < inputArray2.length; i++) { outputArray[i + outputArrayLength] = inputArray2[i]; } return outputArray; } }