Java Iterator Size count(Iterator iterator)

Here you can find the source of count(Iterator iterator)

Description

Determines the number of elements in an iteration.

License

Apache License

Parameter

Parameter Description
iterator a parameter

Declaration

public static long count(Iterator<String> iterator) 

Method Source Code

//package com.java2s;
/*/*  w ww .  j av a2  s . com*/
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 *     http://duracloud.org/license/
 */

import java.util.Iterator;

public class Main {
    /**
     * Determines the number of elements in an iteration.
     *
     * @param iterator
     * @return
     */
    public static long count(Iterator<String> iterator) {
        if (iterator == null) {
            return 0;
        }
        long count = 0;
        while (iterator.hasNext()) {
            ++count;
            iterator.next();
        }
        return count;
    }
}

Related

  1. count(final Iterator iterator)
  2. count(Iterator triples)
  3. count(Iterator it)
  4. counter(final Iterator iterator)
  5. size(final Iterator iter)
  6. size(Iterator source)