static L replaceSublist(L l, L x, L y) { if (x == null) ret l; int i = 0; while (true) { i = indexOfSubList(l, x, i); if (i < 0) break; // It's inefficient :D for (int j = 0; j < l(x); j++) l.remove(i); l.addAll(i, y); i += l(y); } ret l; } static L replaceSublist(L l, int fromIndex, int toIndex, L y) { // inefficient while (toIndex > fromIndex) l.remove(--toIndex); l.addAll(fromIndex, y); ret l; }