What's the Java equivalent to C++'s for_each template?
<p>In the following code you're able to apply any Function f (e.g., add, subtract, etc.). How do I do that through Java?</p>

<pre><code>template&lt;class InputIterator, class Function&gt;
  Function for_each(InputIterator first, InputIterator last, Function f)
  {
    for ( ; first!=last; ++first ) f(*first);
    return f;
  }
</code></pre>
