1// ! IMPORTANTE !
2// in JAVA an array is not the same as an ArrayList object!!
3// 1 - declare, instanciate and populate
4int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5// 2 - declare and instanciate an int array with maxSize
6// note: the index goes between 0 and maxSize-1
7int newarr[] = new int[maxSize];
8// 2.1 - insert the value n on the position pos
9newarr[pos] = n;
10// 2.2 - insert values recursively
11for (i = 0; i < maxSize; i++) { newarr[i] = arr[i]; }
1public static int[] addPos(int[] a, int pos, int num) {
2 int[] result = new int[a.length];
3 for(int i = 0; i < pos; i++)
4 result[i] = a[i];
5 result[pos] = num;
6 for(int i = pos + 1; i < a.length; i++)
7 result[i] = a[i - 1];
8 return result;
9}
10