1. /*
  2. * @(#)Iterator.java 1.10 01/11/29
  3. *
  4. * Copyright 2002 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>
  17. *
  18. * @author Josh Bloch
  19. * @version 1.10 11/29/01
  20. * @see Collection
  21. * @see ListIterator
  22. * @see Enumeration
  23. * @since JDK1.2
  24. */
  25. public interface Iterator {
  26. /**
  27. * Returns <tt>true</tt> if the iteration has more elements. (In other
  28. * words, returns <tt>true</tt> if <tt>next</tt> would return an element
  29. * rather than throwing an exception.)
  30. *
  31. * @return <tt>true</tt> if the iterator has more elements.
  32. */
  33. boolean hasNext();
  34. /**
  35. * Returns the next element in the interation.
  36. *
  37. * @returns the next element in the interation.
  38. * @exception NoSuchElementException iteration has no more elements.
  39. */
  40. Object next();
  41. /**
  42. *
  43. * Removes from the underlying collection the last element returned by the
  44. * iterator (optional operation). This method can be called only once per
  45. * call to <tt>next</tt>. The behavior of an iterator is unspecified if
  46. * the underlying collection is modified while the iteration is in
  47. * progress in any way other than by calling this method.
  48. *
  49. * @exception UnsupportedOperationException if the <tt>remove</tt>
  50. * operation is not supported by this Iterator.
  51. * @exception IllegalStateException if the <tt>next</tt> method has not
  52. * yet been called, or the <tt>remove</tt> method has already
  53. * been called after the last call to the <tt>next</tt>
  54. * method.
  55. */
  56. void remove();
  57. }