配列のマージ
配列と配列をマージして一つの配列にします。
System.arraycopyメソッドを使用すると簡単に実現できます。

サンプルソース
public static Object[] merzeArray(Object[] obj1,Object[] obj2){

    Object[][] obj = new Object[2][];
    obj[0] = obj1;
    obj[1] = obj2;
    
    if(obj[0] == null && obj[1] == null){
        return new Object[0];
    }else if(obj[0] == null){
        return obj[1];
    }else if(obj[1] == null){
        return obj[0];
    }
    
    int size = 0;
    for (int i=0; i<obj.length; i++) {
        size += obj[i].length;
    }

    Object[] returnObj = new Object[size];

    int point = 0;
    for (int i=0; i<obj.length; i++) {
        System.arraycopy(obj[i], 0, returnObj, point, obj[i].length);
        point += obj[i].length;
    }
    return returnObj;
}

Back to top

Information