如何获取数组的子索引值

时间:2015-03-24 10:09:56

标签: java arrays indexing

我们有这样的数组

[
    [6:02:48 , 06:06:20, 2015-03-24, Tuesday, kuja], 
    [06:06:20, 06:15:25, 2015-03-24, Tuesday, rahu], 
    [06:15:25, 06:23:30, 2015-03-24, Tuesday, guru],
    [06:23:30, 06:33:05, 2015-03-24, Tuesday, shani], 
    [06:33:05, 06:41:40, 2015-03-24, Tuesday, budha], 
    [06:41:40, 06:45:12, 2015-03-24, Tuesday, kethu],
    [06:45:12, 06:55:18, 2015-03-24, Tuesday, shukra]
]

当我们打印数组upsublist.get(o); 输出来自[6:02:48 , 06:06:20, 2015-03-24, Tuesday, kuja]

我们只需要获得一个像kuja or rahu or guru这样的值。请告诉我。如何获得只有一个值

我们尝试过upsublist.get(o).get(4) 我们得到了这个enter image description here

1 个答案:

答案 0 :(得分:1)

如果[6:02:48 , 06:06:20, 2015-03-24, Tuesday, kuja]是一个数组并且它的长度始终为5,那么您只需编写upsublist.get(o)[4]即可获得最后一个元素。如果它是一个ArrayList,您可以编写upsublist.get(o).get(4)

如果长度不固定,则必须找到最后一个元素的索引 - upsublist.get(o)[upsublist.get(o).length - 1]