Lab 8 and 9 - Array
Lab 8 and 9 - Array
can be accessed using an index. The elements in an array are typically of the same type (e.g.,
integers, strings).
Example:
Arrays are useful for organizing and managing collections of data efficiently.
In the case of arrays, you can convert them into a stream and then use forEach.
import java.util.Arrays;
1. Single-Dimensional Array
Example (Java):
// Single-dimensional array
2. Two-Dimensional Array
Example (Java):
int[][] arr = {
{1, 2, 3},
{4, 5, 6}
};
3. Ragged Array
A ragged array (or jagged array) is an array of arrays where the inner arrays can have different
lengths.
Example (Java):
int[][] arr = {
{1, 2, 3},
{4, 5},
{6, 7, 8, 9}
};
4. Multi-Dimensional Array
A multi-dimensional array is an array with more than two dimensions (like 3D arrays, 4D
arrays, etc.).
Example (Java):
int[][][] arr = {
{1, 2},
{3, 4}
},
{5, 6},
{7, 8}
};
Summary:
● Multi-Dimensional Array: Arrays with more than two dimensions (3D, 4D, etc.).
Each of these array types is useful depending on the complexity of the data and how you want
to store or manipulate it.