Arrays
Introduction.
Arrays have been a topic of importance in every programming language I
have ever learned. Usually, arrays
are a collection of items or elements of a common data type that
are referenced by a common name, but gain unique identification with
numbers. For example,
The overall array has a name called FirstName. Each of its elements are
Other possibilities exist, such as
In this instance the numberings correspond to the planet's average distance from the Sun. As you might expect there are reasons to have higher dimensional arrays such as the following. |
Orb[1,1] = Mercury | ||
Orb[2,1] = Venus | ||
Orb[3,1] = Earth | Orb[3,2] = Moon | |
Orb[4,1] = Mars | Orb[4,2] = Phobos | Orb[4,2] = Deimos |
Orb[5,1] = Jupiter | sixteen moons |
My understanding is that Jupiter is considered to have
16 moons, which I am not going to list out. Now if you also consider artificial satellites such as those launched by people on Earth, you would need a third dimension to the array of unknown depth. You can also easily have an array of something like dates.
Here the numbering of the array elements increases as the date is more recent. Finally, we talk about the issue of numbering. By default arrays in Java start with numbering at 0. This can make some associations between numbers and contents a bit difficult at times. But once you start working with this approach you'll adjust. The following diagram represents some of the basic syntax and properties for arrays. |