01 /*
02 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
03 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04 *
05 * This code is free software; you can redistribute it and/or modify it
06 * under the terms of the GNU General Public License version 2 only, as
07 * published by the Free Software Foundation. Sun designates this
08 * particular file as subject to the "Classpath" exception as provided
09 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package java.util;
27
28 /**
29 * An iterator over a collection. {@code Iterator} takes the place of
30 * {@link Enumeration} in the Java Collections Framework. Iterators
31 * differ from enumerations in two ways:
32 *
33 * <ul>
34 * <li> Iterators allow the caller to remove elements from the
35 * underlying collection during the iteration with well-defined
36 * semantics.
37 * <li> Method names have been improved.
38 * </ul>
39 *
40 * <p>This interface is a member of the
41 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
42 * Java Collections Framework</a>.
43 *
44 * @author Josh Bloch
45 * @version 1.34, 07/30/07
46 * @see Collection
47 * @see ListIterator
48 * @see Iterable
49 * @since 1.2
50 */
51 public interface Iterator<E> {
52 /**
53 * Returns {@code true} if the iteration has more elements.
54 * (In other words, returns {@code true} if {@link #next} would
55 * return an element rather than throwing an exception.)
56 *
57 * @return {@code true} if the iteration has more elements
58 */
59 boolean hasNext();
60
61 /**
62 * Returns the next element in the iteration.
63 *
64 * @return the next element in the iteration
65 * @throws NoSuchElementException if the iteration has no more elements
66 */
67 E next();
68
69 /**
70 * Removes from the underlying collection the last element returned
71 * by this iterator (optional operation). This method can be called
72 * only once per call to {@link #next}. The behavior of an iterator
73 * is unspecified if the underlying collection is modified while the
74 * iteration is in progress in any way other than by calling this
75 * method.
76 *
77 * @throws UnsupportedOperationException if the {@code remove}
78 * operation is not supported by this iterator
79 *
80 * @throws IllegalStateException if the {@code next} method has not
81 * yet been called, or the {@code remove} method has already
82 * been called after the last call to the {@code next}
83 * method
84 */
85 void remove();
86 }
|