List of utility methods to do ListIterator Usage
Iterator | castIterator(final Iterator Creates a iterator of the desired type based on the given iterator Warning This operation is not type safe. return new Iterator<D>() { private final Iterator<S> it = iterator; @Override public boolean hasNext() { return it.hasNext(); @SuppressWarnings("unchecked") @Override ... |
ArrayList | clearNulls(Collection clear Nulls ArrayList<T> list = new ArrayList<T>(col.size()); for (T t : col) { if (t != null) { list.add(t); return list; |
boolean | containsUsingListIteratorNext(List contains Using List Iterator Next boolean found = false; for (ListIterator<Integer> it = list.listIterator(); it.hasNext();) { if (it.next().equals(value)) found = true; return found; |
String | createCommaSeparatedListOfFullTypeNames(ListIterator create Comma Separated List Of Full Type Names if ((strIt == null) || !strIt.hasNext()) return null; StringBuilder res = new StringBuilder(strIt.next()); while (strIt.hasNext()) { res.append(", "); res.append(strIt.next()); return res.toString(); ... |
int | differingDigits(final int lhs, final int rhs, final int base) differing Digits final List<Integer> lhsDigits = digits(lhs, new ArrayList<Integer>(), base); final List<Integer> rhsDigits = digits(rhs, new ArrayList<Integer>(), base); if (lhsDigits.size() != rhsDigits.size()) return rhs; int index = 0; for (Iterator<Integer> rhsIt = rhsDigits.iterator(), lhsIt = lhsDigits.iterator(); rhsIt.hasNext(); index++) if (rhsIt.next() != lhsIt.next()) return toInt(rhsDigits.subList(index, rhsDigits.size()), base); ... |
ListIterator | emptyIterator() empty Iterator return (ListIterator<T>) EMPTY_ITERATOR;
|
List | filterStringList(final String prefix, final String infix, final String suffix, final List list) Filters the given list of strings, taking all elements that start with the given prefix, contain the given infix and end with the given suffix and returning them as a new list. if ((list == null) || list.isEmpty()) { return new ArrayList(); final List result = new ArrayList(list); final ListIterator iter = result.listIterator(); while (iter.hasNext()) { final String rowName = (String) iter.next(); if (prefix != null) { ... |
int | findFirstIterator(List extends T> list, int fromIndex, int toIndex, T value, Comparator super T> comparator) Finds the first index where the value is located or the index where it could be inserted, similar to the regular binarySearch() methods, but it works with duplicate elements. int a = fromIndex; int b = toIndex; ListIterator<? extends T> it = list.listIterator(); while (a <= b) { int mid = a + (b - a) / 2; T midVal = get(it, mid); int c = comparator.compare(midVal, value); if (c < 0) { ... |
int | findObject(Object item, ListIterator> iter) Finds an item by iterating through the specified iterator. while (iter.hasNext()) { Object o = iter.next(); if (item == null ? o == null : item.equals(o)) { return iter.previousIndex(); return -1; |
T | findPrevious(ListIterator find Previous T prev = null; iter.previous(); if (iter.hasPrevious()) { prev = iter.previous(); iter.next(); iter.next(); return prev; ... |