4.3.10 Describe the characteristics and applications of a collection
Important: the order is not known A collection is like a linked-list, but the order of elements is not guaranteed.
Collection methods in Pseudocode are:
• .addItem( new data item )
• .resetNext( ) start at beginning of list
• .hasNext( ) checks whether there are still more items in the list
• .getNext( ) retrieve the next item in the list
• .isEmpty( ) check whether the list is empty
Some applications for lists
• Useful for group of items when you don’t know how many items you’ll be needing/using (contrast to arrays where the size is set in stone at creation)
• Because the collection is only as big as you need it to be, it is an efficient use of RAM (memory)
• Can be of any data type (primitive or even your own object)