ArrayList/LinkedList 获取第一个索引号

ArrayList/LinkedList get First Index number

是否有可能从第一个索引的第一个数字中取出ArrayList

这是一个例子:

其中有 5 个项目:

path = {0.5,5.0},{0.6,6.0},{0.7,7.0},{0.8,8.0},{0.9,9.0}

我想从 {0.5,5.0} 中得到数字 5.0...

我用 path.get(0) 试过了,但它只给了我 {0.5,5.0} 回来。

是否可以在不获取所有其他数字的情况下从中获取 5.0

如果你的花括号在ArrayList are actually brackets(他们可能是),你可以使用:

myArray.get(0)[index] 得到你想要的索引。在您的示例中是:

myArray.get(0)[1];

注意:如果您的 ArrayList 元素也是 ArrayList,那么您需要使用 get(0).get(1) 而不是 get(0)[1]

如果您的 ArrayList 包含数组,这就是方法

myList.get(0)[1] // You're getting the index 1 from the 1st array of your ArrayList

否则,如果它包含其他ArrayList's

myList.get(0).get(1) // Same logic as above applied to the Collection