Understanding Java Arrays
In Java, the array is referenced with a single variable name that is combined with an index number that is enclosed in brackets. Accessing a certain element in a Java array would require writing the variable name with a specific index number for the said element.
An array in itself is considered as an object. The whole array can be taken as a single object rather than as composed of a group of elements by stating only the variable name without the index number. For example, if y[3] is considered as an element of an array, then y refers to the whole array itself.
It is also important for Java users to be aware that index numbering starts at 0 instead of one. If an element is named y[3], it is actually the fourth element found in the array and not the third, as stated. This will especially be a confusing thing for programmers who might have gotten used to languages with the arrays with indices that start from 1 instead of 0.
Another thing that Java users should know about arrays is that an array has a fixed length that can be set when the array is being created. The length will determine the number of elements that can be stored in the array. The maximum index value that can be used with an array is one less than the length of the array. If a user creates an array of ten elements, then the elements can only use the value from 0 to 9 for its index.
Java should also know that when arrays have already been created, their lengths can no longer be changed. Access to the length of an array can be done by using the length field in the array variable. Using arrays is a great way of storing data with several values that are of the same type and that are logically related to one another.
Arrays can be used for lists of names, lists of invoices, etc. but users should also be aware that such lists have to work with fixed-lengths. There are other types of data structures that you can use in Java if you are working with data having an unknown number of variables or one that changes.
