Java Utililty Methods ListIterator Usage

List of utility methods to do ListIterator Usage

Description

The list of methods to do ListIterator Usage are organized into topic(s).

Method

LinkedListgetAll_SequentialAccess(List idxs, List values)
Takes all values specified by the given idxs (which must be in ascending order) from values through the use of a ListIterator.
LinkedList<V> taken = new LinkedList<V>();
ListIterator<V> valueIter = values.listIterator();
int valuesIdx = -1;
V value = null;
int lastIdx = -1;
for (int idx : idxs) {
    assert idx >= lastIdx;
    lastIdx = idx; 
...
LinkedListgetCamelNameSegments(String camelName)
Returns the list of segments used in a camel style name.
if (camelName == null || camelName.length() == 0) {
    return null;
@SuppressWarnings("rawtypes")
LinkedList segmentList = new LinkedList();
String segment = new String();
segment += camelName.charAt(0);
boolean wasDigit = false;
...
EgetCurrentElement(ListIterator listIterator)
get Current Element
listIterator.previous();
return listIterator.next();
EgetLastNonNull(List l)
Returns the last non-null element in the given list; or, if there is no non-null element, it returns null.
if (l == null) {
    return null;
ListIterator<E> i = l.listIterator(l.size());
while (i.hasPrevious()) {
    E e = i.previous();
    if (e != null) {
        return e;
...
voidgoToFirst(ListIterator iterator)
Move the iterator to the first element.
while (iterator.hasPrevious()) {
    iterator.previous();
voidgotoIndex(ListIterator iterator, int index)
goto Index
int steps = index - iterator.nextIndex();
if (steps < 0) {
    steps = 0 - steps;
    for (int i = 0; i < steps; i++) {
        iterator.previous();
} else {
    for (int i = 0; i < steps; i++) {
...
ObjectincrementalComponentWiseAverageArbitraryDepth(Object average, int n, Object newItems)
A more general version of incrementalComputationOfComponentWiseAverage(List, int, List) that operates on lists of lists of arbitrary depth, including depth 0, that is, on Number s.
if (average instanceof Number) {
    return (((Number) average).doubleValue() * n + ((Number) newItems).doubleValue()) / (n + 1);
ListIterator averageIterator = ((List<Number>) average).listIterator();
ListIterator newItemsIt = ((List) newItems).listIterator();
while (averageIterator.hasNext()) {
    Object averageElement = averageIterator.next();
    Object newItemsElement = newItemsIt.next();
...
intindexOf(List list, E object)
Returns the index of object in list or -1 if the list does not contain the object.
for (ListIterator<E> it = list.listIterator(); it.hasNext();) {
    if (it.next().equals(object)) {
        return it.previousIndex();
return -1;
voidinsertBefore(List list, E... elements)
insert Before
if (list != null) {
    ListIterator<E> iIterator = list.listIterator();
    for (E newElement : elements) {
        iIterator.add(newElement);
voidintern(ListIterator in)
intern
while (in.hasNext()) {
    in.set(in.next().intern());