public static <T extends Comparable<? super T>> void mergeLinkedLists(List<T> to, List<T> from, int maxEntryCount) {
        int entryCount = 0;
        ListIterator<T> i = to.listIterator();
        while (!from.isEmpty()) {
            T fromElement = from.remove(0);
            while (i.hasNext()) {
                T toElement = i.next();
                if (toElement.compareTo(fromElement) > 0) {
                    i.previous();
                    break;
                } else {
                    entryCount++;
                    if (entryCount >= maxEntryCount) {
                        break;
                    }
                }
            }
            if (entryCount >= maxEntryCount) {
                break;
            }
            i.add(fromElement);
            entryCount++;
            if (entryCount >= maxEntryCount) {
                break;
            }
        }
        while (i.hasNext()) {
            i.next();
            i.remove();
        }
    }
A list merger that merges two sorted lists.

@author Ulf Carlin
container-search/src/main/java/com/yahoo/vespa/streamingvisitors/ListMerger.java