Created
December 17, 2015 14:06
-
-
Save Nata01/d3ef3c81c8082ca846ae to your computer and use it in GitHub Desktop.
Insertion of element into array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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