I'm trying to replace values in an array while removing extra values. This is what I have, but it doesn't seem to work and I have no idea why.
I'm just challenging myself to not use any Strings in my project. This will be the last step.
/**
*
* @param original The original array (will be overwritten)
* @param start The start index (inclusive) to replace
* @param end The end index (exclusive) to replace
* @param replacement The array to put starting at <bold>start</bold> and ending at
* <code>replacement.length + start</code> **Note** If <code>end - start > replacement.length</code>
* then all values at <code>replacement.length + start</code> to <code>end</code> will be removed.
*/
private static char[]replace(char [] original, int start, int end, char [] replacement){
char[] lower = new char[start];
for(int i = 0; i < start; i ++){
lower[i] = original[i];
}
char[] upper = new char[original.length - end];
for(int i = 0; i < original.length - end; i ++){
upper[i] = original[i + end];
}
char[] full = new char[start + (original.length - end) + replacement.length];
for(int i = 0; i < lower.length; i ++){
full[i] = lower[i];
}
for(int i = 0; i < replacement.length; i ++){
full[i + start] = replacement[i];
}
for(int i = 0; i < upper.length - end; i ++){
full[i + end] = upper[i];
}
return full;
}