title: Idiom for pairwise iteration through a sorted collection
body: <p>Is there a Java idiom for pairwise iteration through the elements of a sorted <code>Collection</code>? By that I mean that each iteration has access to one element of the collection and the next element of the collection?</p>
  
  <p>For sorted <code>List</code>s (and arrays), it can be done using an index into the collection:</p>
  
  <pre><code> final int n = list.size();
   assert 2 &lt;= n;
   for (int i = 0; i &lt; n - 1; ++i) {
      final Thing thing1 = list.get(i);
      final Thing thing2 = list.get(i+1);
      operateOnAdjacentPair(thing1, thing2);
   }
  </code></pre>
  
  <p>But what about <code>SortedSet</code>? (for <code>SortedMap</code> you can use its <code>entrySet()</code>, which is equivalent to the <code>SortedSet</code> case).</p>
  
  <hr>
  
  <p>So, for example, if your sorted set contained the values {1, 2, 3, 4}, the iterations would be for the pairs (1, 2), (2, 3), (3, 4), in that order.</p>