Unit 5 - Collections, Lists, Maps, Roles of Types Flashcards
In principle, there are two different approaches how types and values can be linked:
- Types intrinsic to values: A type owned by a value. A value has a unique type.
- Types as value classifiers: Types are patterns describing a range of values. For each
classifying type, each value either is or is not conforming to this type. A value can
conform to several such types.
Values have intrinsic types to facilitate
dynamic checking and inspection.
Variables, method parameters and method return values (or other value holders) have
classifying types so that only certain values can be associated with them.
A collection is a
composite value that holds a number of component values that can be easily added, removed or changed.
Collections can be categorised two criteria
as homogeneous vs heterogeneous
and as
fixed-size vs dynamic
Homogeneous, also known as uniform, collections are those
where all elements in each collection have the same type.
Heterogeneous collections are those
where one can mix values of different types in one collection. The values may conform to a classifying type that permits a wide variety of intrinsic types.
Examples of fixed-size collections are Java…
arrays
Examples of dynamic collections are Java…
lists, sets and maps.
Collections are further classified by the kind of abstract structure that holds the components together:
- Sequences
- Maps
- Sets
Collections are further classified by the kind of abstract structure that holds the components together:
Sequences
Components form a linear structure that can be used to refer to particular components (eg 101st component), and can be altered by explicit instructions (eg insert an element at the back of a list).
Collections are further classified by the kind of abstract structure that holds the components together:
Maps
(also known as dictionaries): Components are stored with unique keys by which they can be identified within the collection. The keys can be of almost any type. When the keys are integers in a range 1 . . . n or 0 . . . (n − 1), the map becomes a sequence.
Collections are further classified by the kind of abstract structure that holds the components together:
Sets
No structure visible to programmer, a component is either there or not and no information is accessible about its position in the set.
N/a
Done up to 5.3 Pg4