Collections Flashcards

1
Q

What is the collection framework?

A

Unified architecture for representing and manipulating collections

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are some benefits of the collection framework?

A
  • Reduced programming effort
  • Reliable and optimised
  • Standard interfaces, so less to learn
  • Implementation of each interface interchangable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three things that are contained in the collection framework?

A

Algorithms
Interfaces
Implementation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a collection?

A

An object that groups multiple elements into a single element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What were the three design goals of the collection framework?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the collection interface

A
  • Root interface in the collection hierarchy
  • Represents a group of objects
  • No direct implementations of this interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the set interface

A

Collection with no duplicates

Need to be careful if elements are mutable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe the sorted set interface

A

Set with a total ordering on elements
Either natural ordering (defined by Comparable) or defined by Comparator
Ordering must be consistent with equals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe the navigable set interface

A

Sorted set extended with navigation methods

Example: Retrieve element closest to given element, iterate in ascending or descending order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe the list interface

A
An ordered collection
Control over where elements are inserted
Access elements by index
Usually allow duplicates
Specialised iterator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe the queue interface

A

Collection for holding elements prior to processing
Typically FIFO
Either throw exception if operation fails or return special value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe the blocking queue interface

A

Queue with additional operations that wait if necessary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe the transfer queue interface

A

Blocking queue with operations to support transfer of data where producers may wait for consumers to receive elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe the Deque interface

A

Linear collection supporting element insertion and removal at both ends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe the BlockingDeque interface

A

Dequeue with additional operations that wait if necessary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Describe the Map interface

A

Mapping from keys to values

No duplicate keys, key maps to at most one value

17
Q

What are the three ways you can view a map?

A

Set of keys
Collection of values
Set of key-value pairs

18
Q

Describe the Sorted Map interface

A

Map until total ordering on keys

Natural ordering or defined by Comparator

19
Q

Describe the Navigable Map interface

A

Sorted map extended with navigation methods

20
Q

Describe the ConcurrentMap interface

A

Provides thread safety and atomicity guarentees

Example methods include putIfAbsent and remove, where remove will only happen if key mapped to value

21
Q

State some considerations for choosing implementations

A
Expected size of data 
Efficiency of operations
Optional Operations
Sorting, iterating
Thread safety
Nulls
22
Q

What is an abstract class?

A

A class that provides some of the code that can be common to multiple implementations of an interface

23
Q

Describe the steps for implementing a new collection

A
  1. Extend appropriate abstract class

2. Provide standard constructors