Java Utililty Methods Iterator from

List of utility methods to do Iterator from

Description

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

Method

intgetMaxLength(Iterator i)
calculate the maximum length of all strings in i.
int max = 0;
while (i.hasNext()) {
    String s = i.next().toString();
    int c = s.length();
    if (c > max)
        max = c;
return max;
...
doublegetPerplexity(Iterator probStream)
get Perplexity
double sum = 0.0f;
return sum;
IteratorgetPersistentKeysIterator(HashMap hashMap)
Returns an iterator for the hash map keys that is not changed by parallel changes to the hash map.
return ((HashMap) hashMap.clone()).keySet().iterator();
StringgetSigLinePastOtherAnnotations(String selfCmprurrentLine, Iterator line_itr)
get Sig Line Past Other Annotations
while (selfCmprurrentLine.trim().startsWith("@")) { 
    selfCmprurrentLine = line_itr.next(); 
return selfCmprurrentLine;
ListgetSomeElements(Iterator iterator, int limit)
get Some Elements
ArrayList<T> list = new ArrayList<>();
int currentAmount = 0;
while (iterator.hasNext() && (currentAmount++ < limit)) {
    list.add(iterator.next());
return list;
ListgetSubList(Iterator iterator, int startIndex, int numberOfItems)
Create a list of objects taken from the given iterator and crop the resulting list according to the startIndex and numberOfItems parameters.
List croppedList = new ArrayList(numberOfItems);
int skippedRecordCount = 0;
int copiedRecordCount = 0;
while (iterator.hasNext()) {
    Object object = iterator.next();
    if (++skippedRecordCount <= startIndex) {
        continue;
    croppedList.add(object);
    if ((numberOfItems != 0) && (++copiedRecordCount >= numberOfItems)) {
        break;
return croppedList;
IteratorgetTypedIterator(Iterator it, Class clz)
get Typed Iterator
return (Iterator<T>) it;
IteratortoIterator(Enumeration enumeration)
Adapt an enumeration to an iterator.
@SuppressWarnings("hiding")
class EnumerationIterator<E> implements Iterator<E> {
    private Enumeration<E> enumeration;
    public EnumerationIterator(Enumeration<E> enumeration) {
        this.enumeration = enumeration;
    public boolean hasNext() {
        return this.enumeration.hasMoreElements();
...