Java Array Concatenate concatArray(Object[] arr1, Object newValue)

Here you can find the source of concatArray(Object[] arr1, Object newValue)

Description

concat Array

License

Open Source License

Declaration

public static Object[] concatArray(Object[] arr1, Object newValue) 

Method Source Code

//package com.java2s;

public class Main {
    public static Object[] concatArray(Object[] arr1, Object newValue) {
        Object[] arr2 = new Object[1];
        arr2[0] = newValue;//w w  w.  j a  va2s.c o m
        return concatArray(arr1, arr2);
    }

    public static Object[] concatArray(Object[] arr1, Object[] arr2) {
        int cnt = 0;
        if (arr1 != null) {
            cnt += arr1.length;
        }
        if (arr2 != null) {
            cnt += arr2.length;
        }
        if (cnt == 0) {
            return null;
        }

        int idx = 0;
        Object[] retValue = new Object[cnt];
        if (arr1 != null) {
            for (int i = 0; i < arr1.length; i++) {
                retValue[idx++] = arr1[i];
            }
        }
        if (arr2 != null) {
            for (int i = 0; i < arr2.length; i++) {
                retValue[idx++] = arr2[i];
            }
        }
        assert (cnt == retValue.length);
        return retValue;
    }
}

Related

  1. concatAllArrays(byte[] data1, byte[]... remaining)
  2. concatArray(byte data1[], byte data2[])
  3. concatArray(byte[] old1, byte[] old2)
  4. concatArray(int[] src, String separator)
  5. concatArray(Object... objects)
  6. concatArray(String string, String[] words)
  7. concatArray(String[] array, int start)
  8. concatArray(String[] array, int start, String def)
  9. concatArray(String[] array, String glue)