April 05
Prde. Ismael H. F. Santos -  ismael@tecgraf.puc-rio.br                                                          2
Collection Iterator - Iteradores
nPercorrer coleções, similares aos objetos Enumeration
npublic interface Iterator<E> {
n  boolean hasNext();
n  E next() throws NoSuchElementException; 
n  void remove() throws UnsupportedOperationException,
n                                  IlegalStateException;                      // Optional !
n} 
nRemoção segura elementos da coleção sendo percorrida
n   List<String> list = new ArrayList<String>();
n   ........ 
n   static void filter(Collection<?> c) { // polimorfismo, funciona com qq objeto CF
n      for (Iterator <?> i = c.iterator(); i.hasNext(); )
n       if (!cond(i.next())) i.remove(); // remove da coleção elementos que não
n    }                                                // satisfazem uma dada condição
n                                                    
n