0

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.

3
  • Please tell us your "problem". A 4D array itself is not a problem... Commented Aug 8, 2011 at 7:56
  • 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. Commented Aug 8, 2011 at 8:16
  • 1
    Java is an OO language. Do yourself a favor and use Collections and Map instead of multi-dimensional arrays Commented Aug 8, 2011 at 8:24

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.