1. /*
  2. * @(#)Iterator.java 1.18 03/01/23
  3. *
  4. * Copyright 2003 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.18, 01/23/03
  24. * @see Collection
  25. * @see ListIterator
  26. * @see Enumeration
  27. * @since 1.2
  28. */
  29. public interface Iterator {
  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.
  40. *
  41. * @return the next element in the iteration.
  42. * @exception NoSuchElementException iteration has no more elements.
  43. */
  44. Object next();
  45. /**
  46. *
  47. * Removes from the underlying collection the last element returned by the
  48. * iterator (optional operation). This method can be called only once per
  49. * call to <tt>next</tt>. The behavior of an iterator is unspecified if
  50. * the underlying collection is modified while the iteration is in
  51. * progress in any way other than by calling this method.
  52. *
  53. * @exception UnsupportedOperationException if the <tt>remove</tt>
  54. * operation is not supported by this Iterator.
  55. * @exception IllegalStateException if the <tt>next</tt> method has not
  56. * yet been called, or the <tt>remove</tt> method has already
  57. * been called after the last call to the <tt>next</tt>
  58. * method.
  59. */
  60. void remove();
  61. }