Iterator.java revision adc854b798c1cfe3bfd4c27d68d5cee38ca617da
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package java.util; 19 20 21/** 22 * An Iterator is used to sequence over a collection of objects. Conceptual, an 23 * iterator is always positioned between two elements of a collection. A fresh 24 * iterator is always positioned in front of the first element. 25 * 26 * If a collection has been changed since its creation, methods {@code next} and 27 * {@code hasNext()} may throw a {@code ConcurrentModificationException}. 28 * Iterators with this behavior are called fail-fast iterators. 29 * 30 * @since Android 1.0 31 */ 32public interface Iterator<E> { 33 /** 34 * Returns whether there are more elements to iterate, i.e. whether the 35 * iterator is positioned in front of an element. 36 * 37 * @return {@code true} if there are more elements, {@code false} otherwise. 38 * @see #next 39 * @since Android 1.0 40 */ 41 public boolean hasNext(); 42 43 /** 44 * Returns the next object in the iteration, i.e. returns the element in 45 * front of the iterator and advances the iterator by one position. 46 * 47 * @return the next object. 48 * @throws NoSuchElementException 49 * if there are no more elements. 50 * @see #hasNext 51 * @since Android 1.0 52 */ 53 public E next(); 54 55 /** 56 * Removes the last object returned by {@code next} from the collection. 57 * This method can only be called once after {@code next} was called. 58 * 59 * @throws UnsupportedOperationException 60 * if removing is not supported by the collection being 61 * iterated. 62 * @throws IllegalStateException 63 * if {@code next} has not been called, or {@code remove} has 64 * already been called after the last call to {@code next}. 65 * @since Android 1.0 66 */ 67 public void remove(); 68} 69