Java Array Concatenate concatenate(double[] p1, double[] p2)

Here you can find the source of concatenate(double[] p1, double[] p2)

Description

concatenate

License

Open Source License

Declaration

public static double[] concatenate(double[] p1, double[] p2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

public class Main {
    public static double[] concatenate(double[] p1, double[] p2) {
        double[] ret = new double[p1.length + p2.length];
        ArrayList<Double> lst = new ArrayList<>();
        for (int i = 0; i < p1.length; i++) {
            lst.add(p1[i]);// w  w  w  .j  a  v a 2 s  .c  o m
        }
        for (int i = 0; i < p2.length; i++) {
            lst.add(p2[i]);
        }
        Double[] d = new Double[p1.length + p2.length];
        d = lst.toArray(d);
        for (int i = 0; i < d.length; i++) {
            ret[i] = d[i];
        }
        return ret;
    }

    public static int[] concatenate(int[] p1, int[] p2) {
        int[] ret = new int[p1.length + p2.length];
        ArrayList<Integer> lst = new ArrayList<>();
        for (int i = 0; i < p1.length; i++) {
            lst.add(p1[i]);
        }
        for (int i = 0; i < p2.length; i++) {
            lst.add(p2[i]);
        }
        Integer[] d = new Integer[p1.length + p2.length];
        d = lst.toArray(d);
        for (int i = 0; i < d.length; i++) {
            ret[i] = d[i];
        }
        return ret;
    }

    public static double[][] add(double[][] a, double[][] b) {
        double[][] d = new double[a.length][a[0].length];
        if (isIdenticalMatrix(a, b)) {
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    d[i][j] = a[i][j] + b[i][j];
                }
            }
        } else {

        }
        return d;
    }

    private static boolean isIdenticalMatrix(double[][] a, double[][] b) {
        if (a.length == b.length && a[0].length == b[0].length) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. concatArrays(T[] first, T[] second)
  2. concatArrays(T[] first, T[] second)
  3. concatByteArrays(final byte[] array1, final byte[] array2)
  4. concatenate(@SuppressWarnings("unchecked") T[]... arrays)
  5. concatenate(byte[] a, byte[] b)
  6. concatenate(float[][] a, float[][] b, int dim)
  7. concatenate(int[]... arrays)
  8. concatenate(Object[] array)
  9. concatenate(Object[] array)