title: Java - How do I refer to the previous and next element during an iteration?
body: <p>When I have a <em>for loop</em>, I use the <code>i</code> to refer to the elements of my array, objects, etc.  </p>
  
  <p>Like:<br>
  Current item: <code>myArray[i]</code><br>
  Next item: <code>myArray[i+1]</code><br>
  Previous item: <code>myArray[i-1]</code>  </p>
  
  <p>But at the moment, I'm using a <strong>foreach</strong> loop ( <code>for (Object elem : col) {</code> ).<br>
  How do I refer to the previous item?<br>
  (I need to do a search an 'array', which I'm doing with <code>for (Object object : getComponents())</code>.  </p>
  
  <p>But when it returns true (so it finds what I look for), it should perform the code on the <em>previous</em> and the <em>next</em> item.  </p>
  
  <p><strong>Clarification:</strong> I have <code>java.awt.Component</code> elements!</p>