Java Array Append ARRAY_AddValueToArray(int new_value, int[] array)

Here you can find the source of ARRAY_AddValueToArray(int new_value, int[] array)

Description

Adds a new value to the int[] array

License

Open Source License

Parameter

Parameter Description
new_value a parameter

Declaration

public static int[] ARRAY_AddValueToArray(int new_value, int[] array) 

Method Source Code

//package com.java2s;
/*Copyright 2008 by Vladimir Polony, Stupy 24, Banska Bystrica, Slovakia
    /*w  ww  .  ja v a 2 s. com*/
This file is part of OpenRep FREE homeopathic software.
    
OpenRep FREE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
OpenRep FREE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with OpenRep FREE.  If not, see <http://www.gnu.org/licenses/>.*/

public class Main {
    /** Adds a new value to the int[] array
     * 
     * @param new_value
     * @return
     */
    public static int[] ARRAY_AddValueToArray(int new_value, int[] array) {
        int arr_length = 1;
        if (array != null && array.length != 0)
            arr_length = array.length + 1;
        int[] result = new int[arr_length];
        for (int x = 0; x < array.length; x++) {
            result[x] = array[x];
        }
        result[result.length - 1] = new_value;
        return result;
    }

    /** Adds a new value to the byte[] array
     * 
     * @param new_value
     * @return
     */
    public static byte[] ARRAY_AddValueToArray(byte new_value, byte[] array) {
        int arr_length = 1;
        if (array != null && array.length != 0)
            arr_length = array.length + 1;
        byte[] result = new byte[arr_length];
        for (int x = 0; x < array.length; x++) {
            result[x] = array[x];
        }
        result[result.length - 1] = new_value;
        return result;
    }
}

Related

  1. appendArray(StringBuilder bld, Object[] array, String sep)
  2. appendArray(StringBuilder sb, int[] arr)
  3. appendArray(StringBuilder sb, T[] array, String delimiter)
  4. appendArrays(byte[] in1, byte[] in2)
  5. appendArrays(final byte[] firstArray, final byte[] secondArray)
  6. arrayAppend(byte[] original, byte[] append)