Java Arrays-1
Java Arrays-1
Lecture 5
Output: 4 A D F P a
The enhanced for loop
• Simplified array processing (read only)
• Iterate once for every elements in an array. Each time the
loop iterates, it copies an array element to a variable.
• General format:
for(datatype elementVariable : array) statement;
Example:
• The first statement creates 10 elements integer array and assigns its
address to the numbers variable.
• The second statement allocate 5 elements integer array and assigns its
address to the numbers variable
Reassigning Array References
• The two sets of brackets in the data type indicate that the
scores variable will reference a two-dimensional array.
Accessing Two-Dimensional Array Elements
Accessing Two-Dimensional Array Elements
Array Initializer
• You can also use an array initializer to declare,
create and initialize a two-dimensional array.
• For example,
Accessing Two-Dimensional Array Elements
Multidimensional Arrays