Title: Collection and List Interfaces
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER > Section: Learning Units - Bb

Presentations and Videos

- Collection and List Interfaces lecture video (Time: 53:00)
- Collection and List Interfaces document

- This lecture discusses the Java data structure interfaces Collection, List. Set, and SortedSet. The classes which implement these interfaces are also discussed: ArrayList, Vector, LinkedList, HashSet, TreeSet.
- The Collection interface is the most generic interface and makes very few assumptions of your data structure. Here are a few of the expected methods you must provide if you implement the Collection interface: add, contains, iterator, remove, size, clear, etc. Note that the method contains will only work if you have a proper "equals" method implemented for the elements stored in the Collection.
- The List interface extends the Collection interface and adds the notion of an ordering to the Collection. In otherwords, we can talk about what position an object has within the collection (i.e. first, second, ... last). ArrayList and LinkedList implement the List interface.
- The Set interface extends the Collection interface and adds the notion of uniqueness. A Set is not allowed to have 2 objects with the same value (as defined by the equals method) in the same Collection. HashSet is an implementation of the Set interface and using a technique called Hashing to implement the Set. Note that a Set has no special ordering of the objects within the Set.
- The SortedSet interface extends the Set interface and adds the notion of ordering to a Set. TreeSet is an implementation of a SortedSet. In addition to each object being unique within the Collection, we will know that with a SortedSet that when we list the elements we will get them sorted based on their natural ordering as defined by the Comparable interface. This means that all objects in the SortedSet will need to implement the Comparable interface.
- Iterators are a must in data structures and they are required of classes which implement the Collection interface.
- The Collections class (bad name ... probably should have been Algorithms) contains a bunch of useful static methods: binarySearch, sort, shuffle, etc.