Overview


A fixed array is a linear, sequential, indexable structure.

A limitation of a fixed array is that we can not change the structure (add or remove) once the array has been constructed. We can reset elements at existing positions. See "Access - Setting" below.

Definition


The array size (or length) is simply a count of its elements.
This is the heart and soul of arrays -- indexes. It's how we navigate and access them.

The indexes are "zero-based" which means:

  • The start of the array is 0
  • The end of the array is (size()-1) or (length-1)
Just another example here to show that we may "picture" arrays as left to right or top to bottom. This is just for "visualization" -- whichever you prefer.
We say that arrays are indexable. That means we can access elements at an index.

A couple of common ways to get array elements:

  • elem = anArray[4]
  • elem = anArray.get(4)
Similar to "getting", we can also set elements at specified indexes.

A couple of common ways to set array elements:

  • anArray[4] = newElem
  • anArray.set(4, newElem)
We can easily use loops to iterate over the array elements.

Here we traverse from the start to the end, e.g. indexes 0 to (length-1)
We can just as easily flip that around and traverse from the last index to the first index -- i.e. from index (length-1) to index 0.


References