使用自定义对象数组

时间:2011-04-13 03:28:33

标签: java android arrays

假设我已经通过

创建了一个对象SpecialResource数组
ArrayList<SpecialResource> masterRes = new ArrayList<SpecialResource>();
masterRes.add(0, new SpecialResource(3,5,0,"Foo Bar"));
.........etc etc many more adds...

假设SpecialResource有一个名为getMax()

的方法

我如何引用数组索引0的getMa x方法?我猜到的每个排列都会产生语法错误。 masterRes<0>.getMax()masterRes(0).getMax()

2 个答案:

答案 0 :(得分:2)

嗯,实际上,它不是一个数组,而是一个集合。而且,为了按索引检索项目,您必须使用get方法:

masterRes.get(0).getMax();

答案 1 :(得分:0)

masterRes.get(0).getMax();

Java / Android API文档将为您提供帮助。

http://androidappdocs.appspot.com/reference/java/util/ArrayList.html