java中的多维数组

发布于 2024-11-28 07:12:41 字数 2219 浏览 0 评论 0原文

我在java中创建了以下字符串多维数组。其顶部外部数组是级别(6 个级别),每个级别下有 4 个不同的子级别(4 个子级别),每个组有单独的 10 组,有头和尾。我想访问 level1->> sublevel1->set1-->head 和 tails ...level3->group4->set7->head 和 tails 依此类推level6->sublevel4->set10->head 和 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"},

                    }
                }
            };

帮我解决这个问题,我认为这对我来说非常感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱她像谁 2024-12-05 07:12:41

无论您的问题是什么,您都不应该使用这种数组,因为您的代码将无法理解且无法维护。

您应该创建一个 Level 类,它将允许访问一组或列表的 SubLevel 实例,这将允许您访问一组或列表的 Group< /code> 实例等。

这将导致代码更具可读性,并允许您将行为封装在这些类中。

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.

甜心 2024-12-05 07:12:41

对多维数组说不,如果关系复杂,而是创建自定义类,否则使用简单的 Map。

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

醉态萌生 2024-12-05 07:12:41

我不知道你实际上想做什么,但看起来你想要做一个从单词到它所在的句子片段的映射 - 尝试 HashMap

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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文