Java Array Add addArray(int[] a, int p)

Here you can find the source of addArray(int[] a, int p)

Description

Add element to the end of the array

License

LGPL

Declaration

public static int[] addArray(int[] a, int p) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**/*from   ww w  .  j  a v  a 2s  .  c o  m*/
     * Add element to the end of the array
     */
    public static int[] addArray(int[] a, int p) {
        int[] b = new int[a.length + 1];

        System.arraycopy(a, 0, b, 0, a.length);
        b[a.length] = p;
        return b;
    }

    /**
     * Add element to the start of the array
     */
    public static int[] addArray(int p, int[] a) {
        int[] b = new int[a.length + 1];

        System.arraycopy(a, 0, b, 1, a.length);
        b[0] = p;
        return b;
    }
}

Related

  1. addArray(double[] array1, double[] array2)
  2. addArray(int[] a, int[] b)
  3. addArray(Object[] Old, Object[] New)
  4. addArray(Object[][] first, Object[][]... more)
  5. addArray(StringBuffer RCode, String name, T[] array, boolean useEquals, boolean isString)