Topic 4.2.2 - Outline The Standard Operations of Collections
Topic 4.2.2 - Outline The Standard Operations of Collections
IB Computer Science
Topic 4.2
Connecting computational
thinking and program design
IB Computer Science
Topic 4.2: 4.2.1 - 4.2.9
Connecting computational
thinking and program design
IB Computer Science
Topic 4: 4.2.2
But what if we want to store integers, arrays, objects, booleans and strings in one
data structure? The answer is to use collections because some collections allow
custom specification of the collection Item elements.
The most significant advantage of collections is that they act like a resizable
array. The programmer does not need to know in advance the number of items
that will be placed in the data structure.
Topic 4: 4.2.2
Standard operations
addItem(): It is used to add an item in the collection (addition). TEMPERATURES
is a collection of temperatures. TEMPERATURES.addItem(32) will add 32 to the
collection TEMPERATURES.
getNext(): It is used to return the first item in the collection when it is first called
(retrieval). A=TEMPERATURES.getNext() will assign the value of the first item in
the collection to the variable A.
getNext() will not remove the item from the collection.
Topic 4: 4.2.2
Additional operations
resetNext(): It is used to restart the iteration through the collection.
TEMPERATURES is a collection of temperatures.