Convert a 2D array to a 1D array

@param array2D
@return
198720
public static Object from2DArrayToArray(final Object array2D) {
        // final Profiler profilerPeriod = new Profiler("from2DArrayToArray");
        // profilerPeriod.start("from2DArrayToArray");
        Object array = null;
        if (array2D.getClass().isArray()) {
            final int lengthY = Array.getLength(array2D);
            if (Array.getLength(array2D) > 0) {
                final Object firstLine = Array.get(array2D, 0);
                int lengthLineX;
                if (firstLine.getClass().isArray()) {
                    lengthLineX = Array.getLength(firstLine);
                    final Class<?> compType = firstLine.getClass().getComponentType();
                    array = Array.newInstance(compType, lengthY * lengthLineX);
                    if (lengthLineX > 0 && lengthY > 0) {
                        for (int y = 0; y < lengthY; y++) {
                            final Object line = Array.get(array2D, y);
                            System.arraycopy(line, 0, array, lengthLineX * y, lengthLineX);
                        }
                    }
                } else { // is not a 2D array
                    array = Array.newInstance(array2D.getClass().getComponentType(), Array.getLength(array2D));
                    System.arraycopy(array2D, 0, array, 0, Array.getLength(array2D));
                }
            } else { // empty array
                if (array2D.getClass().getComponentType().isArray()) {
                    array = Array.newInstance(array2D.getClass().getComponentType().getComponentType(),
                            Array.getLength(array2D));
                } else {
                    array = Array.newInstance(array2D.getClass().getComponentType(), Array.getLength(array2D));
                }
            }
        } else { // is not an array
            array = array2D;
        }
        // profilerPeriod.stop().print();
        return array;
    }
872903
public long[] toPrimitiveArray(long[] array) {
	for (int i = 0, j = 0; i < array.length; ++i) {
	    int index = -1;
	    if (j < indices.length && (index = indices[j]) == i) {
		array[i] = values[j];
		j++;
	    }
	    else
		array[i] = 0;
	}

	return array;
    }
918466
public static double[] convertToDoubleArray(Matrix4d transformationMatrix) {
		// Initialise the output array
		double[] outArray = new double[16];
		// Iterate over the matrix
		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				// Now set this element
				outArray[i*4+j] = transformationMatrix.getElement(i,j);
			}
		}
		return outArray;
	}
1349073
public static List<Integer> toIntegerList(int[] array) {
        List<Integer> result = new ArrayList<Integer>(array.length);
        for (int partitionId : array) {
            result.add(partitionId);
        }
        return result;
    }
1153145
public static <T> T[] listToArray(List<T> list, T[] array) {
        if (list == null || array == null) {
            return null;
        }

        return list.toArray(array);
    }
181190
public final Object get2d(Object key1, Object key2) {
        AssociativeArray tmp = internalData.get(key1);
        if(tmp == null) {
            return null;
        }
        
        return tmp.internalData.get(key2);
    }
887474
public double[][] to2D(double[] weights) {
    double[][] newWeights = new double[map.length][];
    int index = 0;
    for (int i = 0; i < map.length; i++) {
      newWeights[i] = new double[labelIndices[map[i]].size()];
      System.arraycopy(weights, index, newWeights[i], 0, labelIndices[map[i]].size());
      index += labelIndices[map[i]].size();
    }
    return newWeights;
  }
434471
private static int[] toIntArray(List<Integer> list) {
		int[] array = new int[list.size()];
		int i = 0;
		for (Integer intObj : list) {
			array[i++] = toInt(intObj);
		}
		return array;
	}
1024695
public final Object put2d(Object key1, Object key2, Object value) {
        AssociativeArray tmp = internalData.get(key1);
        if(tmp == null) {
            internalData.put(key1, new AssociativeArray());
        }
        
        return internalData.get(key1).internalData.put(key2, value);
    }
1213020
public static <T> List<T> arrayToList(T [] array) {
        return new ArrayList<T>(Arrays.asList(array));
    }
891735
public static float[] toFloat(int[] array) {
        float[] n = new float[array.length];
        for (int i = 0; i < array.length; i++) {
            n[i] = (float) array[i];
        }
        return n;
    }
162877
private String stringArray2String(String[] array) {
        StringBuilder sb = new StringBuilder("");
        for (int i = 0 ; i<array.length ; i++) {
            sb.append(array[i]);
            if (i<array.length - 1)
                sb.append("\n");
        }
        return sb.toString();
    }
1215029
public static <T> List<T> arrayToList(T[] array) {
        List<T> list = null;
        if (array != null) {
            list = new ArrayList<>();
            for (T e : array) {
                list.add(e);
            }
        }
        return list;
    }
928972
public static byte[] add(byte[] array, byte[] array2) {
		byte[] newArray = new byte[array.length + array2.length];
		System.arraycopy(array, 0, newArray, 0, array.length);
		System.arraycopy(array2, 0, newArray, array.length, array2.length);
		return newArray;
	}
1015163
public ArrayContainer toArrayContainer() {
    ArrayContainer ac = new ArrayContainer(cardinality);
    ac.loadData(this);
    if (ac.getCardinality() != cardinality) {
      throw new RuntimeException("Internal error.");
    }
    return ac;
  }
1118349
public static Vector2d convert(Tuple2D<?> tuple) {
		if (tuple instanceof Vector2d) {
			return (Vector2d) tuple;
		}
		return new Vector2d(tuple.getX(), tuple.getY());
	}
1157280
public double[] gridToGridArray(double[][][] grid) {
        if (grid == null) {
            grid = this.grid;
        }
        gridArray = new double[dim[0] * dim[1] * dim[2] + 3];
        int dimCounter = 0;
        for (int z = 0; z < grid[0][0].length; z++) {
            for (int y = 0; y < grid[0].length; y++) {
                for (int x = 0; x < grid.length; x++) {
                    gridArray[dimCounter] = grid[x][y][z];
                    dimCounter++;
                }
            }
        }
        return gridArray;
    }