01-11-2012, 03:32 PM
Arrays
Arrays.ppt (Size: 43 KB / Downloads: 21)
An array is a named collection of data items with exactly the same data type.
The set of elements is identified by the name of the set.
The individual elements are identified by their position in the set.
In Java
The type of the members may be any valid Java object or primitive, including another array
Features of Arrays
The Size of array may be determined,
Dynamically! At run-time!
We refer to members of arrays by their index
array[index]
Indices
Start at 0
Extends through size-1
Must be integer compatible
Arrays know their own size!
array.length
Arrays & Methods
When we identify an individual member of an array, we are providing a copy (if it is a primitive)
When we identify the entire array, we are providing access to the entire array
Examples
getLetterGrade( midterms[42] );
findHighScore( midterms );
Vectors Versus Arrays
Vectors are like arrays
They have a size
They contain a number items
The items have an order
Vectors are not like arrays
The size is not fixed
The items do not always have the same type
The order is easily changed
Some Final Words
Parallel Arrays
Using the same index to get information from several different arrays
Should be done with a single array, and each array containing an object
Objects and Arrays
A child object qualifies as it's parent
A Vehicle Array my hold Luxury and PickUp objects