java中的多维数组 [英] Multidimensional array in java

查看:48
本文介绍了java中的多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在java中创建了以下字符串多维数组.顶部外部阵列是级别(6 级),每个级别下有 4 个不同的子级别(4 个子级别),每个组有单独的 10 组,有头和尾.我想访问 level1->>sublevel1->set1-->head and tails ...level3->group4->set7->head and tails 等等直到level6->sublevel4->set10->head and tails.

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.

您应该创建一个 Level 类,它可以访问一组或一系列 SubLevel 实例,这应该可以让您访问一组或一系列 Group 实例等

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.

这篇关于java中的多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆