CS 4773 Object Oriented Systems Java Collections


Topics:


Collection Interface
The most important methods in the interface are as follows:

  • boolean add(E o);
    returns true if the collection changed, false if not.
    some collections do not allow duplicates.
    may throw an exception if object cannot be added.
  • int size();
  • Object[] toArray();
  • Iterator iterator();
    Returns an iterator for this collection. An Iterator has the following main methods: Some of the methods are optional and can throw an exception if not allowed for a particular type of collection.

    The collections in Java 5 are all generic, meaning you can specify the type of the objects in the collection.

    Look at the full Collection interface in the Java documentation.


    Some Concrete Collections
    See Core Java Volume 2, chapter 2 for a complete list.