Calling arraylist object function on entire arraylist

Hi everyone,

pseudocode below:

class Class
{
   void function()
   {
      instruction performed by object;
   }
}

ArrayList<Class> objectList = new ArrayList(100);

for(int i = 0; i < 100; i++)
{
   objectList.get(i).Function();
}

my question is, is it possible to call this function on every object without a loop?
so something like ArrayList.Function()?

for (final Class c : objectList) c.function();

1 Like