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