You are here

Arrays in Java

15 January, 2016 - 09:02
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/402b20ad-c01f-45f1-9743-05eadb1f710e@37.6
  • Arrays...
    • are contiguous (in memory) sets of object references (or values, for primitives),
    • are objects,
    • are dynamically created (via new), and
    • may be assigned to variables of type Object or primitives
  • An array object contains zero or more unnamed variables of the same type. These variables are commonly called the elements of the array.
  • A non-negative integer is used to name each element. For example, arrayOfInts[i] refers to the i+1st element in the arrayOfInts array. In computer-ese, an array is said to be a "random access" container, because you can directly (and I suppose, randomly) access any element in the array.
  • An array has a limited amount of intelligence, for instance, it does know its maximum length at all times, e.g. arrayOfInts.length.
  • Arrays have the advantage that they
    • provide random access to any element
    • are fast
    • require minimum amounts of memory

More information on arrays can be found in the Java Resources web site page on arrays.

Note: Arrays are size and speed at a price.