import java.util.ArrayList;

/**
 * Demonstrates basic features of the ArrayList class.
 * 
 * @author Drue Coles
 */
public class ListOfAnimals {

    public static void main(String[] args) {
        
        ArrayList<String> animals = new ArrayList<>();
        animals.add("porcupine");
        animals.add("iguana");
        animals.add("capybara");
        animals.add("quokka");
        animals.add("vulture");
        
        // Output contents of list.
        for (int i = 0; i < animals.size(); i++) {
            System.out.print(animals.get(i) + " ");
        }
        System.out.println();
        
        // Output contents using for-each loop.
        for (String a : animals) {
            System.out.print(a + " ");
        }
        System.out.println();

        // Insert an animal, remove one, and add another.
        animals.add(2, "anaconda");
        animals.remove(4);
        animals.add("okapi");
        
        // Output contents using for-each loop.
        for (String a : animals) {
            System.out.print(a + " ");
        }
        System.out.println();       
    }    
}