Code example for Collection

Methods: iterator, size

0
     * 
     * @throws NoSuchElementException if there are no elements 
     *                                at all.  Use {@link #hasNext} to avoid this error. 
     */ 
    public E next() { 
        if (collection.size() == 0) {
            throw new NoSuchElementException("There are no elements for this iterator to loop on");
        } 
        if (iterator.hasNext() == false) {
            reset(); 
        } 
        return iterator.next();
    } 
 
    /** 
     * Removes the previously retrieved item from the underlying collection. 
     * <p/> 
     * This feature is only supported if the underlying collection's 
     * {@link Collection#iterator iterator} method returns an implementation 
     * that supports it. 
     * <p/> 
     * This method can only be called after at least one {@link #next} method call. 
     * After a removal, the remove method may not be called again until another 
     * next has been performed. If the {@link #reset} is called, then remove may 
     * not be called until {@link #next} is called again. 
     */ 
    public void remove() { 
        iterator.remove();
    } 
 
    /** 
     * Resets the iterator back to the start of the collection. 
     */ 
    public void reset() { 
        iterator = collection.iterator();
    } 
 
    /** 
     * Gets the size of the collection underlying the iterator. 
     *