【发布时间】:2014-03-10 11:45:22
【问题描述】:
我已经学会了如何Create an Arraylist of Objects,这样的数组本质上是动态的。例如要创建具有 3 个字段的对象数组(类矩阵的实例),代码如下所示:
ArrayList<Matrices> list = new ArrayList<Matrices>();
list.add( new Matrices(1,1,10) );
list.add( new Matrices(1,2,20) );
此外,Matrices 类是这样的:
public class Matrices{
int x;
int y;
int z;
Matrices(int x,int y, int z){
this.x = x;
this.y = y;
this.z = z;
}
}
现在,我如何访问此数组名称 list 中任何元素的每个字段?具体来说,如何从该数组的第二个元素(其值为(1,2,20))访问20字段?
【问题讨论】:
-
请检查 Java API 以了解这些基本问题。