CS 121 Lecture Notes - Lecture 78: Abstract Data Type
Collection & Data Structures:
Collection: an object that serves as a repository for other objects.
oA generic term that can be applied to many situations.
oUsually used when discussing an object whose specific role is to provide
services to add, remove, & otherwise manage elements that are contained
within.
EX: The ArrayList class represents a collection.
Provides methods to add elements to end of a list or to a particular
location in the list based on an index value.
Provides methods to remove specific elements as needed.
oSome collections maintain elements in a specific order, while others
don’t.
Some collections are homogeneous: they can contain all of the same
type of object.
Other collections are heterogeneous: they can contain objects of
various types.
An ArrayList that doesn’t specify an explicit element type can
be thought of as heterogeneous b/c it can hold an object of any
type.
Its heterogeneous nature comes from the fact that an ArrayList
stores Object references.
It can store any object b/c of inheritance & polymorphism:
the condition of occurring in several different forms.
Separating Interface From Implementation
A crucial aspect of collections is that they can be implemented in a variety of
ways.
oUnderlying data structure that stores objects can be implemented using
various techniques.
find more resources at oneclass.com
find more resources at oneclass.com
Document Summary
Ex: the arraylist class represents a collection. Provides methods to add elements to end of a list or to a particular location in the list based on an index value. Provides methods to remove specific elements as needed: some collections maintain elements in a specific order, while others don"t. Some collections are homogeneous: they can contain all of the same type of object. Other collections are heterogeneous: they can contain objects of various types. An arraylist that doesn"t specify an explicit element type can be thought of as heterogeneous b/c it can hold an object of any type. Its heterogeneous nature comes from the fact that an arraylist stores object references. It can store any object b/c of inheritance & polymorphism: the condition of occurring in several different forms. All operations on an arraylist are accomplished by invoking methods that perform appropriate operations on the underlying array.