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

IteratortoIterator(final T[] data)
Creates an iterator over the supplied array.
if (data == null) {
    return null;
return new Iterator<T>() {
    public boolean hasNext() {
        return (_index < data.length);
    public T next() {
...
MaptoMap(final Iterator> iterator)

Generics equivalent of commons-collections' IteratorUtils.toMap()

final Map<K, V> ret = new HashMap<K, V>();
Map.Entry<K, V> entry;
while (iterator.hasNext()) {
    entry = iterator.next();
    ret.put(entry.getKey(), entry.getValue());
return ret;
IteratortoObjectIterator(Object[] objects)
to Object Iterator
return Arrays.asList(objects).iterator();
SettoSet(Iterator iteration)
to Set
Set<T> elements = new HashSet<T>(1);
while (iteration.hasNext()) {
    elements.add(iteration.next());
return elements;
StringtoString(Iterator iterObjects)
to String
return toString(iterObjects, false);
StringtoString(Iterator tokens)
to String
Iterable<String> iterable = () -> tokens;
return String.join(" ", iterable);
String[]toStringArray(Iterator iterator)
Creates a new array of String objects, containing the elements of a supplied Iterator.
if (null == iterator) {
    return new String[0];
ArrayList<String> strings = new ArrayList<>();
while (iterator.hasNext()) {
    strings.add(iterator.next());
String[] string_array = new String[strings.size()];
...
Object[]unwrapIterator(Iterator iter)
unwrap Iterator
ArrayList<Object> ret = new ArrayList<Object>();
while (iter.hasNext()) {
    ret.add(iter.next());
return ret.toArray();