author | darcy |
Fri, 19 Aug 2011 17:42:24 -0700 | |
changeset 10350 | 6d009f117062 |
parent 7668 | d4a77089c587 |
child 16929 | c984ae5655cb |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 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 |
* |
|
4977
81902a400bbf
6929382: Various core classes in util and elsewhere are missing @param <T> tags
darcy
parents:
2
diff
changeset
|
44 |
* @param <E> the type of elements returned by this iterator |
81902a400bbf
6929382: Various core classes in util and elsewhere are missing @param <T> tags
darcy
parents:
2
diff
changeset
|
45 |
* |
2 | 46 |
* @author Josh Bloch |
47 |
* @see Collection |
|
48 |
* @see ListIterator |
|
49 |
* @see Iterable |
|
50 |
* @since 1.2 |
|
51 |
*/ |
|
52 |
public interface Iterator<E> { |
|
53 |
/** |
|
54 |
* Returns {@code true} if the iteration has more elements. |
|
55 |
* (In other words, returns {@code true} if {@link #next} would |
|
56 |
* return an element rather than throwing an exception.) |
|
57 |
* |
|
58 |
* @return {@code true} if the iteration has more elements |
|
59 |
*/ |
|
60 |
boolean hasNext(); |
|
61 |
||
62 |
/** |
|
63 |
* Returns the next element in the iteration. |
|
64 |
* |
|
65 |
* @return the next element in the iteration |
|
66 |
* @throws NoSuchElementException if the iteration has no more elements |
|
67 |
*/ |
|
68 |
E next(); |
|
69 |
||
70 |
/** |
|
71 |
* Removes from the underlying collection the last element returned |
|
72 |
* by this iterator (optional operation). This method can be called |
|
73 |
* only once per call to {@link #next}. The behavior of an iterator |
|
74 |
* is unspecified if the underlying collection is modified while the |
|
75 |
* iteration is in progress in any way other than by calling this |
|
76 |
* method. |
|
77 |
* |
|
78 |
* @throws UnsupportedOperationException if the {@code remove} |
|
79 |
* operation is not supported by this iterator |
|
80 |
* |
|
81 |
* @throws IllegalStateException if the {@code next} method has not |
|
82 |
* yet been called, or the {@code remove} method has already |
|
83 |
* been called after the last call to the {@code next} |
|
84 |
* method |
|
85 |
*/ |
|
86 |
void remove(); |
|
87 |
} |