lunes, 27 de julio de 2009

Aca voy a poner varios ejemplos de como recorrer vectores, arrays, o colecciones de datos como list, etc etc.....

Como recorrer un HashTable:

Hashtable a = getHashTable();

Enumeration e = a.keys();
Object obj;
while (e.hasMoreElements()) {
obj = e.nextElement();
System.out.println("clave "+ obj +": " + a.get(obj));
}


------------------------------------------------------------------------------------------

Como recorrer un MAP:


Map hm = new HashMap();
hm.put("1","Luis");
hm.put("2","Amaya");
hm.put("3","Julio");
Iterator it = hm.entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next();
System.out.println(e.getKey() + " " + e.getValue());

No hay comentarios:

Publicar un comentario