I am trying to write a method with a variable length parameter to "add" to an existing array. I understand I must copy the original array, but I don't understand how to take in the variable length parameter, create the copy with more length, and add the new values in order to the new array. This was for an assignment that I couldn't complete. Not allowed arraylist due to professor instruction. I am not very knowledgeable in coding, if anyone could assist further.
...
protected double[] purchase;
...
protected void addPurchases(double ... purchase2Add){
int addMe = purchase2Add.length - 1;
for(int i = 0; i < purchase2Add.length; i++){
if(0 == 0){
break;
}
}
purchase = Arrays.copyOf(purchase, purchase2Add.length + addMe);
}
This is all I could come up with. The if statement is placeholder. I was thinking of how to take each parameter value and place it in the new indexes the the purchase array, but I am not really knowing how to do that.