An object that groups multiple elements into a single unit
Collections
Used to store, retrieve, manipulate, and communicate aggregate data
Typically represent data items that form a natural group
Examples of collections
Poker hand (a collection of cards)
Mail folder (a collection of letters)
Telephone directory (a mapping from names to phone numbers)
Collection interface
Stores groups of Objects, with duplicates allowed
Set interface
Extends Collection but forbids duplicates
List interface
Extends Collection, allows duplicates, and introduces positional indexing
Map
A separate hierarchy from Collection
Java does not provide any direct implementations of Collection. Rather, concrete implementations are based on other interfaces which extend Collection, such as Set, List, etc.
The most general code will be written using Collection to type variables
Map
An object that associates keys with values
A map cannot contain duplicate keys; each key can map to at most one value
Map implementations
HashMap<K,V>
Hashtable<K,V>
TreeMap<K,V>
Iterator
An object that cycles through all the elements in a collection
Iterator interface
Has methods: next(), hasNext(), remove()
ListIterator
Extends the Iterator interface, designed to work with collections that satisfy the List interface
Can move in either direction along a list of elements
Has methods to modify elements
Iterators for standard collection classes return references, not copies, so modifying the returned value will modify the element in the collection
Differences between Iterator and ListIterator
Iterator can traverse elements in forward direction only, ListIterator can traverse in both forward and backward directions
Iterator can traverse Map, List and Set, ListIterator can only traverse List
Iterator cannot obtain indexes, ListIterator has methods to obtain indexes
Iterator cannot modify or replace elements, ListIterator can modify or replace elements
Iterator cannot add elements, ListIterator can add elements