ArrayList Loop Patterns


Review: Stepping through an ArrayList of Fish

    // Construct a list (initially empty) that could hold fish.
    // Then construct many new fish and add them to the list.
    .
    .
    .

    // Move each fish forward, without changing direction.
    for ( int i = 0; i < fishList.size(); i++ )
    {
        AquaFish f = fishList.get(i);
        f.moveForward();
        // Or, fishList.get(i).moveForward();
    }

Alyce Brady, Kalamazoo College