01-11-2012, 03:30 PM
Vectors
Vectors.ppt (Size: 49.5 KB / Downloads: 22)
Course Updates
Update to the on-line Grades has been posted
Schedule now reflects what was announced in class
You may use Vectors or Arrays in this assignment
Although the list was kept short to avoid that
Collections
Often we want to group things together
A collection, group, list, set
The individual distinctiveness of an element may only be the member's position in the the collective
Java has an Abstract Data Type (ADT) which supports this
The Vector
Poor Name
ADT?
A collection of data structures and algorithms
Implementation details may not be known
Vectors - A Description
A Vector is a Java API defined class
java.util
It may hold any number of objects
Any element is of type Object
It can grow or shrink as needed!
Methods are available to
Add elements to the collection
Remove elements to the collection
Traverse the collection
Traversing Vectors
Often we want to visit every member of the collection
And perform some action
Such as adding 10% to the total grade
Testing for equality
To do this with Vectors, we need help
We need the methods from the Enumeration Interface
The Enumeration Interface
There are two methods from the interface
hasMoreElements()
returns true if there are more elements
nextElement()
returns the next element in the enumeration
We can get an Enumeration 'object' from the class which implements the collection
Putting the enumeration to work
We have the vector of vehicles
vehicleList
We have some number of cars in there
Create an Enumeration object for the list of vehicles
Traverse the list, asking each vehicle to show itself