title: Is there an elegant way of doing something to the last element of a for-each loop in Java?
body: <p>I'm using Java 6.</p>
  
  <p>Suppose I had a bunch of cats to feed, and suppose myCats is sorted.</p>
  
  <pre><code>for (Cat cat : myCats) {
  
      feedDryFood(cat);
  
      //if this is the last cat (my favorite), give her a tuna
      if (...) 
          alsoFeedTuna(cat);
  }
  </code></pre>
  
  <p>and I wanted to treat my last cat specially.</p>
  
  <p>Is there a way to do this elegantly inside the loop? The only way I can think of is counting them.</p>
  
  <p>Stepping back a little bit for a wider picture, is there any programming language that supports this little feature in a for-each loop?</p>