Here you can find the source of mergeArrays(String[] data1, String[] data2)
Parameter | Description |
---|---|
data1 | - first array of string |
data2 | - second array of string |
public static synchronized String[] mergeArrays(String[] data1, String[] data2)
//package com.java2s; /*/*from w w w. j a v a 2s. c o m*/ Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ public class Main { /** * Merge 2 string's arrays data1 and data2 to one array of string 'data1 + * data2'. * * @param data1 - first array of string * @param data2 - second array of string * @return - merged array or null if both arrays is null */ public static synchronized String[] mergeArrays(String[] data1, String[] data2) { if (data1 == null && data2 == null) { return null; } if (data1 == null) { return data2; } if (data2 == null) { return data1; } int cnt = 0; String[] retVal = new String[data1.length + data2.length]; for (int i = 0; i < data1.length; i++) { retVal[cnt++] = data1[i]; } for (int i = 0; i < data2.length; i++) { retVal[cnt++] = data2[i]; } return retVal; } }