All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jdroid.java.collections.Iterators Maven / Gradle / Ivy

package com.jdroid.java.collections;

import java.util.Iterator;

public class Iterators {
	
	/**
	 * Returns the number of elements remaining in {@code iterator}. The iterator will be left exhausted: its
	 * {@code hasNext()} method will return {@code false}.
	 * 
	 * @param iterator The {@link Iterator}
	 * @return The {@link Iterator} size
	 */
	public static int size(Iterator iterator) {
		int count = 0;
		while (iterator.hasNext()) {
			iterator.next();
			count++;
		}
		return count;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy