How to do a for loop over a nested ArrayList?

Viewed 6470

I'm going to make this 2D rendering engine as modular as I possibly can. I've come up with, but haven't yet finished, a priority list for drawing/updating sprites, so that I can control which sprites are in front of each other.

This code is meant to loop through each priority list and render every sprite in that list.

//I don't entirely understand what this for-each type of loop does.

public static void renderSprites(ArrayList<ArrayList<AbstractSprite>> priorities){
    for (ArrayList<AbstractSprite> priority : priorities){
        for(AbstractSprite sprite : priorities.get(priority)){

           renderSprite(/* what should I reference to get the relevant sprite? */);

           //this is my best guess at what the nested loop would be, but it obviously doesn't work.
          //any ideas?
        }
    }
}
3 Answers
Related