Explore BrainMass

How to program arrays in Java

If you were explaining an array ti a friend who is learning Java. how would you do so?
How would you explain how arrays are used?
Provide at least one concrete example.

Solution Preview

You can store Java program data in variables. Each variable has:
- An identifier,
- A type, and
- A scope.

When you have closely related data of the same type and scope, it is often convenient to store it together in a data structure instead of in individual variables. The most common data structure is the array. Arrays are fixed-length structures for storing multiple values of the same type. An array implicitly extends java.lang.Object so an array is an instance of Object. But arrays are directly supported language features. This means that their performance is on par with primitives and that they have a unique syntax that is different than objects.

Array elements:

0 1 2
|1st | 2nd | 3rd |

* Structure of Java Arrays
The Java array depicted above has 3 elements. Each element in an array holds a distinct value. In the figure, the number above each element shows that element's index. Elements are always referenced by their indices. The ...

Solution Summary

How arrays are used in Java is explained.