1. /*
  2. * @(#)Iterator.java 1.24 04/01/17
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.util;
  8. /**
  9. * An iterator over a collection. Iterator takes the place of Enumeration in
  10. * the Java collections framework. Iterators differ from enumerations in two
  11. * ways: <ul>
  12. * <li> Iterators allow the caller to remove elements from the
  13. * underlying collection during the iteration with well-defined
  14. * semantics.
  15. * <li> Method names have been improved.
  16. * </ul><p>
  17. *
  18. * This interface is a member of the
  19. * <a href="{@docRoot}/../guide/collections/index.html">
  20. * Java Collections Framework</a>.
  21. *
  22. * @author Josh Bloch
  23. * @version 1.24, 01/17/04
  24. * @see Collection
  25. * @see ListIterator
  26. * @see Enumeration
  27. * @since 1.2
  28. */
  29. public interface Iterator<E> {
  30. /**
  31. * Returns <tt>true</tt> if the iteration has more elements. (In other
  32. * words, returns <tt>true</tt> if <tt>next</tt> would return an element
  33. * rather than throwing an exception.)
  34. *
  35. * @return <tt>true</tt> if the iterator has more elements.
  36. */
  37. boolean hasNext();
  38. /**
  39. * Returns the next element in the iteration. Calling this method
  40. * repeatedly until the {@link #hasNext()} method returns false will
  41. * return each element in the underlying collection exactly once.
  42. *
  43. * @return the next element in the iteration.
  44. * @exception NoSuchElementException iteration has no more elements.
  45. */
  46. E next();
  47. /**
  48. *
  49. * Removes from the underlying collection the last element returned by the
  50. * iterator (optional operation). This method can be called only once per
  51. * call to <tt>next</tt>. The behavior of an iterator is unspecified if
  52. * the underlying collection is modified while the iteration is in
  53. * progress in any way other than by calling this method.
  54. *
  55. * @exception UnsupportedOperationException if the <tt>remove</tt>
  56. * operation is not supported by this Iterator.
  57. * @exception IllegalStateException if the <tt>next</tt> method has not
  58. * yet been called, or the <tt>remove</tt> method has already
  59. * been called after the last call to the <tt>next</tt>
  60. * method.
  61. */
  62. void remove();
  63. }