import ballerina/io;function main (string[] args) {
int[] a = [];
io:println(lengthof a);
a = [1, 2, 3, 4, 5, 6, 7, 8];
io:println(lengthof a);
a[999] = 23;
io:println(a[999]);
io:println(lengthof a);
}
ArraysAll arrays are unbounded in length and support a 0 based indexing. Arrays can be sparse and grow upto any length based on the given index, as long as there is available memory. |
|
import ballerina/io;
|
|
function main (string[] args) {
|
|
int[] a = [];
io:println(lengthof a);
|
Create an int array of length 0. |
a = [1, 2, 3, 4, 5, 6, 7, 8];
io:println(lengthof a);
|
Create an array with initially assigned values. |
a[999] = 23;
io:println(a[999]);
io:println(lengthof a);
}
|
Arrays are unbounded in length. They can grow upto any length based on the given index. For example, the length of the following array is 1000. |
$ ballerina run arrays.bal
0
8
23
1000
|
|