import ballerina/io;function main (string[] args) {
int[][] xx = [[1, 2, 3], [10, 20, 30], [5, 6, 7]];
io:println(lengthof xx);
io:println(lengthof xx[0]);
int[][][] xxx = [xx];
xxx[0][0][1] = 10;
io:println(xxx[0][0][1]);
int[][] aa = [];
int[] a = [9];
aa[0] = a;
io:println(xx[0][0]);
}
Array of ArraysBallerina supports array of arrays. The following example shows how to initialize, set, and access values from an array of arrays. |
|
import ballerina/io;
|
|
function main (string[] args) {
|
|
int[][] xx = [[1, 2, 3], [10, 20, 30], [5, 6, 7]];
io:println(lengthof xx);
io:println(lengthof xx[0]);
|
This is how you can initialize an array of int arrays. |
int[][][] xxx = [xx];
xxx[0][0][1] = 10;
io:println(xxx[0][0][1]);
|
This is how to initialize a three-dimensional array with one value. In this case, the value is a two-dimensional array. |
int[][] aa = [];
|
Initialize the outermost array of the two dimensional array with an empty value. |
int[] a = [9];
aa[0] = a;
|
Set the initialized one-dimensional array to the two-dimensional array. |
io:println(xx[0][0]);
}
|
Print the first value of the two-dimensional array. |
$ ballerina run array-of-arrays.bal
3
3
10
1
|
|