|
Do you need help with your Java programming?
Click here for instant help with your Java code. |
Accessing Array Elements
Array elements are accessed through using the square brackets notations and specifying the element index within them. As said earlier, the first index in an array is 0, so it we were to assign the first element in an array to another variable it could look like this: |
int[] numbers = new int[] {10, 11, 12}; //The variable 'aNumber' is assigned the value 10 int aNumber = numbers[0]; |
The variable that is assigned the value must be of the same data type as the elements of the array. The exception is a super class type to a reference type. As a matter of fact, the first element in the array as well as all other elements is variables too. The difference between them and other variables is that a normal variable is accessed through a name but an array variable has no name and is accessed through an index value. |
| Previous | Next | |
Tutorial Home | ||
| Do you know your Java? | |
| Take a Ten-Question-Java-Quiz! | |
Search for code examples on this site
