You need to sign in to do that
Don't have an account?
How to Implement 3 dimension array in Apex
Hi All,
I am trying to implement the three dimension array in apex, could any one let me know where I am getting struck.
/* Here goes my java snippet */
private static int[][][] MAX_LENGTH = { { {41, 25, 17, 10}, {34, 20, 14, 8}, {27, 16, 11, 7}, {17, 10, 7, 4} }, { {77, 47, 32, 20}, {63, 38, 26, 16}, {48, 29, 20, 12}, {34, 20, 14, 8} }, { {461, 279, 192, 118}, {365, 221, 152, 93}, {259, 157, 108, 66}, {202, 122, 84, 52} }, { {552, 335, 230, 141}, {432, 262, 180, 111}, {312, 189, 130, 80}, {235, 143, 98, 60} }};
/* Apex Snippet */
private static List<List<List<Integer>>> MAX_LENGTH = { List<Integer> { List<Integer>{41, 25, 17, 10}, List<Integer> {34, 20, 14, 8}, List<Integer> {27, 16, 11, 7}, List<Integer>{17, 10, 7, 4} }, List<Integer> { {77, 47, 32, 20}, List<Integer>{63, 38, 26, 16}, List<Integer>{48, 29, 20, 12}, List<Integer>{34, 20, 14, 8} }, List<Integer> { List<Integer>{461, 279, 192, 118}, List<Integer>{365, 221, 152, 93}, List<Integer>{259, 157, 108, 66}, List<Integer>{202, 122, 84, 52} }, List<Integer> { List<Integer>{552, 335, 230, 141}, List<Integer>{432, 262, 180, 111}, List<Integer>{312, 189, 130, 80}, List<Integer>{235, 143, 98, 60} }
};
It would be appreciative if any one could give there ideas or solution. Thanks in advance.
Regards ,
Zubair Haris.
I could not find an elegant way to do this, but here is a way that works. My code does not exactly fit your example, but you can see how it works...
I hope this helps.
All Answers
I could not find an elegant way to do this, but here is a way that works. My code does not exactly fit your example, but you can see how it works...
I hope this helps.
The three dimensional List is probably the best you can do in Apex.
If I were you, I'd build a layer of abstraction around it and create a simple API into the 3-D List so you didn't have to use it so awkwardly.
Hi Ryan,
Could you please illustrate a bit so that how can I implement the 3d concept using list.
Regards,
Zubair.
new List<List<String>>{ new List<String> {'T1','T2','T3','T4'}, new List<String> {'T11','T12','T13','T14'} },
new List<List<String>>{ new List<String> {'T11','T12','T13','T14'}, new List<String> {'T21','T22','T23','T24'} },
new List<List<String>>{ new List<String> {'T21','T22','T23','T24'}, new List<String> {'T31','T32','T33','T34'} }
};
System.debug(numbers[0]);
System.debug(numbers[0][1]);
System.debug(numbers[0][1][2]);