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

booleanhasNexts(List> heads)
has Nexts
return heads.stream().anyMatch(Iterator::hasNext);
booleanhasOpenIteratorsRequiringOpenConnection()
Returns whether there is at least one open iterator which requires an open connection
final Map<Iterator<?>, Boolean> iterators = OPEN_ITERATORS.get();
if (iterators != null) {
    for (final Boolean requiresOpenConnection : iterators.values()) {
        if (Boolean.TRUE.equals(requiresOpenConnection)) {
            return true;
return false;
inthex(Iterator it)
hex
if (it.hasNext()) {
    Integer nx = it.next();
    if (nx == '%') {
        int hi = Character.digit(it.next(), 16);
        int lo = Character.digit(it.next(), 16);
        return ((hi << 4) | lo) & 0x3f;
    } else
        return nx;
...
Stringimplode(Iterator it)
implode
StringBuilder sb = new StringBuilder();
while (it.hasNext()) {
    sb.append(it.next());
    sb.append(", ");
return sb.toString().replaceAll(", +$", "");
booleanisBlank(Iterator iterator)
is Blank
return !isPresent(iterator);
booleanisIterator(Class clazz)
is Iterator
return Iterator.class.isAssignableFrom(clazz);
booleanisPrefixOf(Iterator pref, Iterator target)
is Prefix Of
while (pref.hasNext()) {
    T v = pref.next();
    if (!target.hasNext()) {
        return false;
    if (!v.equals(target.next())) {
        return false;
return true;
Iterableiterable(Iterator iterator)
Allow iterator to be used in a for each loop.
return new Iterable<T>() {
    @Override
    public Iterator<T> iterator() {
        return iterator;
};
intlength(Iterator iter)
length
int len = 0;
while (iter.hasNext()) {
    iter.next();
    ++len;
return len;
Iteratorlimit(final Iterator iterator, final int limit)
limit
return new Iterator<R>() {
    private int iterated;
    @Override
    public boolean hasNext() {
        return iterated < limit && iterator.hasNext();
    @Override
    public R next() {
...