Java, copy array A to array B from index point using for loop
I am trying to copy entries in the array questionLineFields to a new array
called testQuestions.
I am trying to copy indices [1 to 3] in questionLineFields not the value
of [0] index.
Here is my current code:
numQuestion = Integer.parseInt(questionLineFields[0]); //**num question is
3**
String[] testQuestions = new String[numQuestion];
for(int i=0;i<numQuestion;i++){
testQuestions[i] = questionLineFields[i+1];
}
This does not work and I receive a ArrayIndexOutOfBoundsException. I have
seen this thread. I would preferably use a for loop as my professor has
requested use of a for loop.
Thanks!
No comments:
Post a Comment