Skip to content

Instantly share code, notes, and snippets.

@toinetoine
Created October 28, 2016 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toinetoine/1fce8093c343812d8fdf99de31013052 to your computer and use it in GitHub Desktop.
Save toinetoine/1fce8093c343812d8fdf99de31013052 to your computer and use it in GitHub Desktop.
splice
public static int[] splice(int a[], int offset, int b[]) {
int[] resultArray = new int[a.length + b.length];
for(int i = 0; i < resultArray.length; i++) {
if (i < offset) { // before the part b should be copied to
resultArray[i] = a[i];
}
else if (i - offset < b.length) { // in the middle of the part b is copied to
resultArray[i] = b[i - offset];
}
else { // after the part b was copied to
resultArray[i] = a[i - b.length];
}
}
return resultArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment