Eric
Eric

Reputation: 1973

Using an array of custom objects

Let's say I've created an array of objects SpecialResource via

ArrayList<SpecialResource> masterRes = new ArrayList<SpecialResource>();
masterRes.add(0, new SpecialResource(3,5,0,"Foo Bar"));
.........etc etc many more adds...

Let's say SpecialResource has a method calledgetMax()

How would I reference the getMax method of array index 0? Every permutation I've guessed at is giving syntax errors. masterRes<0>.getMax(), masterRes(0).getMax(), etc.

Upvotes: 1

Views: 681

Answers (2)

DenMark
DenMark

Reputation: 1628

masterRes.get(0).getMax();

Java/Android API document will help you.

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

Upvotes: 0

Cristian
Cristian

Reputation: 200130

Well, actually, it's not an array, but a collection. And, in order to retrieve its items by index, you must use the get method:

masterRes.get(0).getMax();

Upvotes: 2

Related Questions