You need to sign in to do that
Don't have an account?
Noam Damri 3
Dealing with two dimension array
Hey,
Ive created a two-dimension array and initialized it like that:
list<list<integer>> two_d_array = new list<list<integer>>();
integer[] one_d_array = new list<integer>();
for(integer i=0 ; i<d2_size ; i++){
for(integer j=0 ; j<d1_size ; j++){
one_d_array.add(0);
}
two_d_array.add(one_d_array);
}
i wanna approach a direct cell like that:
two_d_array[2][3] = 1289;
or (do the same thing)
two_d_array.get(2).set(3, 1289);
The problem is, by doing it it assign all column [3] as 1289.
The array will be like:
[0][3] = 1289
[1][3] = 1289
[2][3] = 1289
etc.
So how can i approach a direct cell. A specific one, not the all column.
Thx a lot!
Ive created a two-dimension array and initialized it like that:
list<list<integer>> two_d_array = new list<list<integer>>();
integer[] one_d_array = new list<integer>();
for(integer i=0 ; i<d2_size ; i++){
for(integer j=0 ; j<d1_size ; j++){
one_d_array.add(0);
}
two_d_array.add(one_d_array);
}
i wanna approach a direct cell like that:
two_d_array[2][3] = 1289;
or (do the same thing)
two_d_array.get(2).set(3, 1289);
The problem is, by doing it it assign all column [3] as 1289.
The array will be like:
[0][3] = 1289
[1][3] = 1289
[2][3] = 1289
etc.
So how can i approach a direct cell. A specific one, not the all column.
Thx a lot!
output:
All Answers
It will get the same results. The whole column 3 will be filled with 'value'.
as the index is 3, two_d_array[0][3] , two_d_array[1][3], two_d_array[2][3], two_d_array[3][3] etc., will be all 'value'.
output:
So actually it is the same logic as in the initilazing i did, you cant approach a direct cell but with a list.
Thank you!
If you are doing matrix work you may want to look at this starting linear algrebra library (https://github.com/pbattisson/Apex-Linear-Algebra)which provides some methods that may make working with this easier for you.