Java tutorial
//package com.java2s; import java.util.*; public class Main { public static Iterator pairs(Collection l) { List x = new LinkedList(); Object prev = null; for (Iterator i = l.iterator(); i.hasNext();) { Object curr = i.next(); if (prev != null) x.add(new Object[] { prev, curr }); prev = curr; } return x.iterator(); } /** Return a new list with <code>o</code> appended to <code>l</code>. */ public static List add(List l, Object o) { l.add(o); return l; } }