I am using a for loop to iterate through a list of arrays that all have the same name expect a different number at the end. For example child1, child2, etc. I though if I tried childi where i is the variable that I would be able to loop through all the arrays. However, that did not work. I have change i from an int to a string and concatenating it on the end, but then I get a new variable that is not the same at the array. Any ideas.
int i=0;
String []child=childi;//so child would refer to child0 then child1
for (int j = 0; j < child.length(); j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, child[j]);
curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
}
i++
You cannot reference a variable by a dynamically computed name. In this case your best bet is probably to create an array or other container to hold your child arrays. For example,