static Chain toChain(Iterable l) { Iterator it = iterator(l); if (!it.hasNext()) null; Chain c = new(it.next()); Chain last = c; int size = 1; while (it.hasNext()) { ++size; Chain x = new(it.next()); last.next = x; last = x; } // update sizes and return Chain x = c; while (x != null) { x.size = size--; x = x.next; } ret c; }