开发者

Multidimensional array in java

I have create following string multidimensional array in java. which has top outer array is level(6 levels)and under each level has 4 different sub-level(4 sub levels) and each group has individual 10 set ,that have head and tails.I want to access level1->>sublevel1->set1-->head and tails ...level3->group4->set7->head and tails and so on up to level6->sublevel4->set10->head and tails.

 final String[][][][] myStr = {
                               {
                                 {                                      

                                    {"it", "it was over"},
                                    {"on","work on it"},

                                 },
                                 {                                      

                                   {"very", "very good girl"},
                                   {"all","all around"},

                                 },
                                                                                                                                                                       {

                                {
                                  {"for", "good for you"},
                                  {"are","are so long"},

                                },
                               {                                        


                                 {"with","with his cat"},
                      开发者_运维百科           {"it", "it was over"},

                               }
                          },

              ...       

                {
                    {                               
                        {"get","get the cat"},
                        {"for", "good for you"},

                    },
                    {                                       

                        {"on","work on it"},
                        {"can","can come here"},

                    },
                    {                               
                        {"as","as long as"},
                        {"but", "but not me"},

                    },
                    {                                       
                        {"aunt","was my aunt"},
                        {"system", "her system was"},

                    }
                }
            };

Help me this problem , i think which is great appreciate to me.


Whatever your problem is, you shouldn't use such a kind of array, because your code will be impossible to understand and unmaintainable.

You should create a Level class, which would give access to a set or list of SubLevel instances, which should give you access to a set or list of Group instances, etc.

This will lead to much more readable code, and allow you to encapsulate behavior in these classes.


Say no to multi-dimensional array, Instead create custom classes if the relation is complex, else use simple Map.


I have no idea what you're actually trying to do, but it looks like you want to do a map from words to the sentence fragment it was found in - try a HashMap<String,String>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜