Collections Flashcards
What is the collection framework?
Unified architecture for representing and manipulating collections
What are some benefits of the collection framework?
- Reduced programming effort
- Reliable and optimised
- Standard interfaces, so less to learn
- Implementation of each interface interchangable
What are the three things that are contained in the collection framework?
Algorithms
Interfaces
Implementation
What is a collection?
An object that groups multiple elements into a single element
What were the three design goals of the collection framework?
- Produce a reasonably small API (size and conceptual weight)
- Small number of core interfaces
- Only have methods if it is a truly fundamental operation or compelling performance reason
Describe the collection interface
- Root interface in the collection hierarchy
- Represents a group of objects
- No direct implementations of this interface
Describe the set interface
Collection with no duplicates
Need to be careful if elements are mutable
Describe the sorted set interface
Set with a total ordering on elements
Either natural ordering (defined by Comparable) or defined by Comparator
Ordering must be consistent with equals
Describe the navigable set interface
Sorted set extended with navigation methods
Example: Retrieve element closest to given element, iterate in ascending or descending order
Describe the list interface
An ordered collection Control over where elements are inserted Access elements by index Usually allow duplicates Specialised iterator
Describe the queue interface
Collection for holding elements prior to processing
Typically FIFO
Either throw exception if operation fails or return special value
Describe the blocking queue interface
Queue with additional operations that wait if necessary
Describe the transfer queue interface
Blocking queue with operations to support transfer of data where producers may wait for consumers to receive elements
Describe the Deque interface
Linear collection supporting element insertion and removal at both ends
Describe the BlockingDeque interface
Dequeue with additional operations that wait if necessary