gpt4 book ai didi

java - 如何在数组列表中引用数组元素?

转载 作者:搜寻专家 更新时间:2023-11-01 02:10:07 24 4
gpt4 key购买 nike

我已经创建了一个 LinkedListString 数组:

public static void main(String[] args){

String[] one = new String[10];
String[] two = new String[10];
String[] three = new String[10];

LinkedList<String[]> myList = new LinkedList<String[]>();

myList.add(one);
myList.add(two);
myList.add(three);

}

我的问题是我现在如何访问其中一个数组的元素。例如,我可以通过以下方式访问(或在示例中打印)整个数组元素:

System.out.println(myList.get(0));

但我如何访问 myList.get(0) 拥有的 String 数组中的第一个元素?我尝试了所有类似 myList.get(0).[0] 的方法,但当数组是链表的元素时,我无法弄清楚如何访问数组中的元素。

最佳答案

array.get(0)[index];

这应该可以解决问题。

array.get(0) 返回一个数组,您所要做的就是在它后面添加索引(没有点分隔)。

就像使用 one[index] 一样。

关于java - 如何在数组列表中引用数组元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20361899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com