Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

how to insert a 0 in an array java

public static int[] addPos(int[] a, int pos, int num) {
    int[] result = new int[a.length];
    for(int i = 0; i < pos; i++)
        result[i] = a[i];
    result[pos] = num;
    for(int i = pos + 1; i < a.length; i++)
        result[i] = a[i - 1];
    return result;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #insert #array #java
ADD COMMENT
Topic
Name
8+9 =