I created the following code:
int storagevar= arrayList.get(0);
for (int j=0; z<(storagevar-1); j++){
someString= normalArray[j];
}
This code looks through an ArrayList
and gets the first element in there, which is a number representing an index in a second (normal) array
containing String
s. It then uses this number to get the information from the second array, and stores it in another String
.
This code is completely fine; it's the next bit thats causing a problem.
The above code assumes there is only 1 element inside the ArrayList
. However, if there is more than one element, then I need to do the operation for each element in the ArrayList
, so if there were 3 elements inside it, I would end up with the 3 indexes, and I would use them to extract the information from the normal array
, and will end up with 3 String
s.
I wrote the code below for the above scenario. I know it doesn't store each element answer in its own String
, and I don't know how to do it; I need help with that too. But anyways, this code doesn't seem to work either:
public void testMethod(){
MyClass test_one = arrayList.get(8);
String[] tmpStringArray = test_one.correct;
ArrayList<Integer> nnaCorrectAnswers = test_one.correctAnswers;
for (int i=0; i<nnaCorrectAnswers.size();i++){
tmp2= nnaCorrectAnswers.get(i);
for (int z=0; z<(tmp2 -1); z++){
someString=tmpStringArray[z];
}
}
}