java中的多维数组
我在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无论您的问题是什么,您都不应该使用这种数组,因为您的代码将无法理解且无法维护。
您应该创建一个
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 ofSubLevel
instances, which should give you access to a set or list ofGroup
instances, etc.This will lead to much more readable code, and allow you to encapsulate behavior in these classes.
对多维数组说不,如果关系复杂,而是创建自定义类,否则使用简单的 Map。
Say no to multi-dimensional array, Instead create custom classes if the relation is complex, else use simple Map.
我不知道你实际上想做什么,但看起来你想要做一个从单词到它所在的句子片段的映射 - 尝试
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>