原文地址:http://sauzny.iteye.com/blog/1700313


// 一维数组合并
private static String[] getMergeArray(String[] al, String[] bl) {
    String[] a = al;
    String[] b = bl;
    String[] c = new String[a.length + b.length];
    System.arraycopy(a, 0, c, 0, a.length);
    System.arraycopy(b, 0, c, a.length, b.length);
    return c;
}

// 二维数组纵向合并
private static String[][] unite(String[][] content1, String[][] content2) {
    String[][] newArrey = new String[][] {};
    List<String[]> list = new ArrayList<String[]>();
    list.addAll(Arrays.<String[]> asList(content1));
    list.addAll(Arrays.<String[]> asList(content2));
    return list.toArray(newArrey);
}

// 二维数组横向合并
public static String[][] getMergeArray(String[][] al, String[][] bl) {
    if(al == null || al.length == 0) return bl;
    if(bl == null || bl.length == 0) return al;
    String[][] newArrey = null;
    // 根据数组的长度,判断要补全哪个数组
    if (al.length > bl.length) {
        newArrey = new String[al.length][];
        // 补全较短的数组
        String[][] temps = new String[al.length - bl.length][bl[0].length];
        for (int i = 0; i < temps.length; i++) {
            for (int j = 0; j < temps[0].length; j++) {
                temps[i][j] = "";
            }
        }
        String[][] btemp = unite(bl, temps);
        // 合并
        for (int k = 0; k < al.length; k++) {
            newArrey[k] = getMergeArray(al[k], btemp[k]);
        }
    } else {
        newArrey = new String[bl.length][];
        String[][] temps = new String[bl.length - al.length][al[0].length];
        for (int i = 0; i < temps.length; i++) {
            for (int j = 0; j < temps[0].length; j++)
                temps[i][j] = "";
        }
        String[][] atemp = unite(al, temps);
        for (int k = 0; k < bl.length; k++) {
            newArrey[k] = getMergeArray(atemp[k], bl[k]);
        }
    }
    return newArrey;
}

原文地址:http://sauzny.iteye.com/blog/1700313