// Compile with "javac Main.java"
// Run with "java Main"

import java.util.ArrayList;

public class Main {

  public static void main(String[] args) {
    
    // Notice: Java will not autobox ArrayList<int> into
    //   ArrayList<Integer> for you!
    
    ArrayList<Integer> cow = new ArrayList<Integer>();
    ArrayList<Double> dog = new ArrayList<Double>();
    ArrayList<String> elephant = new ArrayList<String>();

    for(int i = 0; i < 10; i ++) {
      cow.add(3 * i);
      dog.add(0.25 * i);
      if(i % 2 == 0)
        elephant.add("Even");
      else
        elephant.add("Odd");
    }
      
    System.out.println("== Generic List Printer ==");
      
    printArrayList(cow);
    printArrayList(dog);
    printArrayList(elephant);
      
    System.out.println();
      
    System.out.println("== Generic Element Accessing ==");

    int    cow_at_7      = getElement(cow, 7);
    double dog_at_2      = getElement(dog, 2);
    String elephant_at_4 = getElement(elephant, 4);

    System.out.println("Cow at 7      = " + cow_at_7);
    System.out.println("Dog at 2      = " + dog_at_2);
    System.out.println("Elephant at 4 = " + elephant_at_4);
  }

    // Java method name convention: lower case + camel case.
    
    static <A> void printArrayList(ArrayList<A> animalList) {
      for(A a : animalList)
        System.out.print(a + "\t");
      System.out.println();
  }
    
    static <A> A getElement(ArrayList<A> what, int which) {
        return what.get(which);
  }
}

