Skip to content

Instantly share code, notes, and snippets.

@Nata01
Created December 17, 2015 14:06
Show Gist options
  • Save Nata01/d3ef3c81c8082ca846ae to your computer and use it in GitHub Desktop.
Save Nata01/d3ef3c81c8082ca846ae to your computer and use it in GitHub Desktop.
Insertion of element into array
public static int[] insertElementIntoArray(int arr[], int position, int elem){
int[] tempArr = new int[arr.length+1];
for (int i = 0; i < position; i++) {
tempArr[i] = arr[i];
}
tempArr[position] = elem;
for (int i = position+1; i < tempArr.length; i++) {
tempArr[i] = arr[i-1];
}
return tempArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment