List is a type of Collection.
List does everything a Collection does... and then some
List has an isEmpty method
List has an add() method
List also has a get method
List also has an add(int index) method
List inherits from Collection
Collection is called a superinterface of List
List is called a subinterface of Collection
List is also a Collection
Collection is not necessarily a List (e.g. Set)
interface List extends Collection {
void add(int index, Object o);
int indexOf(Object o);
Object get(int index);
Object remove(int index);
Object set(int index);
}
Collection interface.
SortedSet and Set
SortedMap and Map
Set and Collection
List.java
List.class file
ArrayList - An Implementation of a Subinterface
class ArrayList implements List {
...
}
List's methods
Collection's methods
ArrayList can be used wherever a List
or a Collection is called for
List [] listArr = new List[10]; ... listArr[i] = new ArrayList();
void doSomething(Collection c) {
Iterator iter = c.iterator();
while (iter.hasNext()) {
... = iter.next();
...
}
}
...
// elsewhere
ArrayList alist = new ArrayList();
...
doSomething(aList);