The java.util.List Interface

The List interface specifes the methods that can be used with any implementing class, such as ArrayList. Programmers should use List as the type name of all list variables, parameters, and method return values.

// Specs for List and ArrayList in java.util (AP only)

interface java.util.List<E>
    int size()
    boolean add(E obj)
    void add(int i, E obj)
    E get(int i)
    E set(int i)
    E remove(int i)

class java.util.ArrayList<E> implements java.util.List<E>


// Example use of List and ArrayList 

List<Integer> numbers = new ArrayList<Integer>();
List<String> names = new ArrayList<String>();

for (int i = 1; i <= 10; i++){
    numbers.add(i);
    names.add("Name " + i);
}

for (int i : numbers)
    System.out.println(i);

for (String name : names)
    System.out.println(name);