import java.util.Arrays;
public class MyClass {
private static int[] InsertElement(int[] arr, int value, int index) {
int[] tmp = new int[arr.length + 1];
System.arraycopy(arr, 0, tmp, 0, index);
tmp[index] = value;
System.arraycopy(arr, index, tmp, index + 1, arr.length - index);
return tmp;
}
public static void main(String args[]) {
int[] arr = { 4, 0, 7, 1, 8 };
int value = 9;
int index = 2;
arr = InsertElement(arr, value, index);
System.out.println(Arrays.toString(arr));
}
}
/*
run:
[4, 0, 9, 7, 1, 8]
*/