ArrayList of Arraylists - retrieving info
in
Programming Questions
•
2 years ago
I am trying to retrieve the data inside a series of ArrayLists out of an ArrayList when passed as an argument inside a
function. I’m not well-versed in Java, but did have a look around on the Java forums for an answer to this question. One solution mentioned the use of the import java.util.ArrayList and
import java.util.Iterator. I did try the suggested answer. Suffice to say, the problem, persists.
import java.util.Iterator. I did try the suggested answer. Suffice to say, the problem, persists.
My code:
void train(int i, ArrayList w)
{
for (int i = w.size()-1; i > 0; --i) //counting backwards through the ArrayList
{
// error in this line: ClassCastException: java.lang.Float cannot be cast to java.util.ArrayList:
ArrayList tempList = (ArrayList) w.get(i);
}
int ndxComposite = findBMU(tempList);
// (etc ...)
}
I have tried substituting the problem line with:
float tempList = (Float) w.get(i);
however, this is casting the outcome as floats, whereas the function is expecting an ArrayList, so I get an error further down in the function. I realise that I can convert the ArrayLists inside the Arraylist to arrays beforehand but would prefer not to, in this case. The code becomes unwieldy.
Any suggestions will be greatly appreciated.
1