I have an array list of objects and I want to use them in a function call. I want to effectively do this:
Code :apples[i].function();
but am unsure how to do this with an array list. Please help.
Printable View
I have an array list of objects and I want to use them in a function call. I want to effectively do this:
Code :apples[i].function();
but am unsure how to do this with an array list. Please help.
The posted code uses an element from an array of objects to call one of its method.
The ArrayList class has methods to return references to an element it holds that can be used like the array referencing that uses an index(theArray[theIndex]). Call the ArrayList class's method to get the object reference and use that to call its method.
K. Thanks. Got it figured out. I was doing it right (not the way posted above), I was just missing a proper cast
If you use generics you should not have to use cast.