Programa De Ejemplo

import java.awt.Color;
import java.util.*;

public class PruebaCollection {
private static final String colores [] = {"rojo","blanco","azul"};

PruebaCollection() {
List lista = new ArrayList();

lista.add( Color.MAGENTA);

for ( int cuenta =0; cuenta < colores.length; cuenta ++)
lista.add ( colores[ cuenta ] );

lista.add ( Color.CYAN);

System.out.println ( "\nArrayList: " );

for ( int cuenta = 0; cuenta < lista.size(); cuenta ++ )
System.out.print ( lista.get ( cuenta ) + " " );

eliminarObjetosString ( lista );

System.out.println ( "\n\n ArrayList despues de llamar eliminarObjetosString: ");

for ( int cuenta = 0; cuenta<lista.size(); cuenta++)
System.out.print( lista.get ( cuenta ) + " " );

}

private void eliminarObjetosString ( Collection coleccion)
{
Iterator iterador = coleccion.iterator();

while ( iterador.hasNext())

if ( iterador.next() instanceof String )
iterador.remove();
}

public static void main ( String args[] )
{
new PruebaCollection();
}

}

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License