Course Content
Introduction to Java
Find the length of an Array
The array's length is the number of elements an array can store. You can use the .length
property to find the number of elements in the array:
Main.java
Loop through an Array
A common way to loop through an array is using a for
loop (we will learn this loop in the next chapter). The for loop will iterate through each element in the array and perform the given operations. Here is an example:
Main.java
Multidimensional Arrays
Multidimensional arrays are also called rectangular arrays in Java. They are often used to store data in a tabular format. The two-dimensional array is a simple case of a multidimensional array in Java.
It can be declared as follows:
The code for creating a two-dimensional array:
Declaration and creation can be combined as the following code:
Main.java
Following is the 2-D array creation for the above code:
Column/Row | Column 1 | Column 2 | Column 3 | Column 4 |
Row 1 | a[0][0] | a[0][1] | a[0][2] | a[0][3] |
Row 2 | a[1][0] | a[1][1] | a[1][2] | a[1][3] |
Row 3 | a[2][0] | a[2][1] | a[2][2] | a[2][3] |
Main.java
Retrieve the second element from array:
Select the correct answer
Section 1.
Chapter 4