Java Utililty Methods Iterator

List of utility methods to do Iterator

Description

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

Method

StringprintContainer(Iterator it, String sep)
print Container
String ret = "";
while (it.hasNext()) {
    ret += it.next().toString();
    if (it.hasNext()) {
        ret += sep;
return ret;
...
voidprintElements(String desc, Iterator i)
Print every element of an iterator to stdout.
printElements("", desc, i);
voidprintIterator(final Iterator iterator)
Helper method for printing the content from an Iterator.
int i = 1;
while (iterator.hasNext()) {
    final T element = iterator.next();
    System.out.println(i + ".)Element:" + element);
    i++;
voidprintIterator(Iterator i, String header)
print Iterator
System.out.println(header);
for (int c = 0; c < header.length(); c++)
    System.out.print("=");
System.out.println();
if (i.hasNext()) {
    while (i.hasNext())
        System.out.println(i.next());
} else
...
voidprintIterator(Iterator> it)
print Iterator
while (it.hasNext()) {
    Map.Entry<K, V> entry = it.next();
    System.out.println(entry.getKey() + "  " + entry.getValue());
voidput(String key, Iterator value)
put
iteratorMap.put(key, value);
MapputAllFromAll(Map map, Iterator> mapsIterator)
Puts all entries from all maps in the range of an iterator to a given map.
for (Map<K, V> eachMap : in(mapsIterator)) {
    map.putAll(eachMap);
return map;
intread(Iterator it, E[] array)
read
int i = 0;
for (; i < array.length && it.hasNext();) {
    E item = it.next();
    if (item != null) {
        array[i++] = item;
return i;
...
SetreduceSet(Iterator> values)
A helper method for set MapReduce.
Set<T> set = new HashSet<>();
while (values.hasNext()) {
    set.addAll(values.next());
return set;
booleanremoveAll(Collection collection, Iterator itemsToRemove)
Removes from a collection all items retrieved from a specified iterator.
boolean modified = false;
while (itemsToRemove.hasNext()) {
    Object o = itemsToRemove.next();
    while (true) {
        if (collection.remove(o)) {
            modified = true;
        } else {
            break;
...