A collection of items of the same type stored continuously in memory, maintaining order.
Traits
Homogenous? | Yes |
---|---|
Static/dynamic? | Static |
Mutable? | Yes |
Example
Usage
public class Main {
public static void main(String[] args) {
int[] arr = new int[10];
// Fill the array list with 10n
for (int i = 0; i < 10; i++) {
arr[i] = 10 * i;
}
// Output the array list
for (int i = 0; i < 10; i++) {
System.out.println(arr[i]);
}
// Update the array list
arr[5] = -1;
// Attempt to update outside the bounds of the array list (error)
arr[11] = 0;
arr[-1] = 0;
}
}
Info
Java example provided as Python does not natively implement arrays, rather using lists.