I'm trying to add an Array with values to an already existing Array which already has one value. My approach, was to create a new Array with the length of the already existing one + the length of the values i want to add. Then i would just loop through the whole Array and add the values to the index of the new Array. My Approach looks like this:
public void addValues(int[] values) {
int[] array = new int[data.length + values.length];
for(int i = 0; i < array.length; i++) {
array[i] = values;
}
data = array;
}
Where as "data" is the already existing Array My appraoch fails because of multiple things,
- I can't convert "array[i] = values"
- I don't have the values of "old" Array
I can't think of a Solution
data.length + values.lengthwhile print array you get errorIndex out of boundbecausearray.length > values.length