Here you can find the source of size(final Iterator
Parameter | Description |
---|---|
E | the element type |
iter | the iterator |
public static <E> int size(final Iterator<E> iter)
//package com.java2s; /**/*from www.ja va 2s.co m*/ * Licensed to the TomTom International B.V. under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. TomTom International B.V. * licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Iterator; public class Main { /** * Returns the number of elements in the iterator sequence. * * The iterator cannot be re-used after calling this function!! * * @param <E> the element type * @param iter the iterator * @return the number of elements */ public static <E> int size(final Iterator<E> iter) { if (iter == null) { throw new NullPointerException(); } int count = 0; while (iter.hasNext()) { iter.next(); count++; } return count; } }