【发布时间】:2015-11-05 17:34:37
【问题描述】:
我有一个像下面这样的对象:
1 [country1, state1, district1, schoolName1, studentName1]
2 [country1, state1, district1, schoolName1, studentName2]
3 [country1, state1, district1, schoolName2, studentName1]
4 [country1, state1, district1, schoolName2, studentName2]
5 [country1, state1, district2, schoolName1, studentName1]
6 [country1, state1, district2, schoolName1, studentName2]
.
.
.
1000 [country3, state4, district2, schoolName2, studentName1]
1001 [country3, state4, district2, schoolName2, studentName2]
.
.
现在我想隔离如下:
[country1]
[state1]
[district1]
[schoolname1]
[studentname1,studentName2,...]
[schoolname2]
[studentname1,studentName2,...]
.
.
[district2]
.
.
[country2]
[state1]
[district1]
[schoolname1]
[studentname1,studentName2,...]
[schoolname2]
[studentname1,studentName2,...]
.
.
[district2]
[schoolName1]
.
.
据我所知,我可以使用嵌套的for 循环。但它消耗更多的时间和性能。我知道这是个坏主意。如果您遇到过这种情况,请分享您的经验以解决此问题。
【问题讨论】:
-
[some text here]是什么意思?这是一个数据结构还是你想打印这样的文本? -
对不起。我需要这样的对象。例如:1个国家对象应该有嵌套的状态对象,一个状态对象应该有多个地区对象。等
标签: java performance for-loop time-complexity