title: How can I reference to an element on an ArrayList of objects. to invoke some method on that object
body: <p>How can I reference an element on an <code>ArrayList</code> of objects to invoke some method on that object.</p>
  
  <p>For example:</p>
  
  <pre><code>//antsNumber is number entered by the user
  Ants antsArray[];
  antsArray=new Ants[antsNumber];
  </code></pre>
  
  <p>Inside <code>Ants</code> object there are some methods.  I want to do something like this if possible..</p>
  
  <pre><code>for(int count=0;count&lt;ants.size();count++){
     ants.elementAt(count).plaplapla;
  }
  </code></pre>
  
  <p>I tried to use foreach:</p>
  
  <pre><code>for(Ants ant:antsArray){
  </code></pre>
  
  <p>But it didn't work because I need to know which is the number of element in this array so I can send it to other method to access it easily.</p>