Code example for NoSuchElementException

0
    static class EmptyIterator implements Iterator {
        public boolean hasNext() { 
            return false; 
        } 
        public Object next() {
            throw new NoSuchElementException();
        } 
        public void remove() { 
            throw new IllegalStateException();
        } 
    } 
 
    /** 
     * Returns an empty iterator in which <tt>hasNext</tt> always returns 
     * <tt>false</tt>. 
     * 
     * @return an empty iterator 
     */ 
    public Iterator iterator() {
        return new EmptyIterator(); 
    }