Java Array Merge mergeStringArrays(String[][] arrayOfArrays)

Here you can find the source of mergeStringArrays(String[][] arrayOfArrays)

Description

Merges an array of string arrays to a concatenated string array.

License

Open Source License

Declaration

public static String[] mergeStringArrays(String[][] arrayOfArrays) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

public class Main {
    /**/*from  www . j  a va  2  s . c o  m*/
     * Merges an array of string arrays to a concatenated 
     * string array.
     * Concatenation is done in the following order 
     * arrayOfArrays[0][0],arrayOfArrays[0][1]  ...  arrayOfArrays[1][0] ... arrayOfArrays[x][z]
     * if arrayOfArrays is <code>null</code> the method return string array with length 0.
     * any <code>null</code> value in <code>arrayOfArrays</code> is skipped. 
     */
    public static String[] mergeStringArrays(String[][] arrayOfArrays) {
        if (arrayOfArrays == null) {
            return new String[0];
        }
        ArrayList<String> res = new ArrayList<String>();
        for (int i = 0; i < arrayOfArrays.length; i++) {
            if (arrayOfArrays[i] == null) {
                continue;
            }
            for (int j = 0; j < arrayOfArrays[i].length; j++) {
                if (arrayOfArrays[i][j] != null) {
                    res.add(arrayOfArrays[i][j]);
                }
            }
        }
        return res.toArray(new String[res.size()]);
    }
}

Related

  1. mergeStringArray(String[] input)
  2. mergeStringArrayFromIndex(String[] arrayString, int i)
  3. mergeStringArrays(String array1[], String array2[])
  4. mergeStringArrays(String array1[], String array2[], String array3[])
  5. mergeStringArrays(String[] array1, String[] array2)
  6. mergeStrings(String[] x, String[] y)
  7. mergeToArray(T... args)