Is there a Java idiom for pairwise iteration through the elements of a sorted Collection
? By that I mean that each iteration has access to one element of the co
You can simply implement it the following way (and apply similar strategy towards other collections):
Iterator iter = set.iterator();
Thing previous = iter.hasNext() ? iter.next() : null;
while (iter.hasNext()) {
final Thing current = iter.next();
operateOnAdjacentPair(previous, current);
previous = current;
}