PDA

View Full Version : [Java]Iteratori


Kleidemos
17-06-2003, 11:02
Esistono in java il corrispondente degli iteratori della lib STL del C++?


Tnk

kingv
17-06-2003, 11:43
tutte le classi "container" (ArrayList, HashMap, ecc.ecc ) ritornano un java.util.Iterator che puoi usare per "scorrere" all'interno dell'oggetto

Kleidemos
17-06-2003, 11:47
ma fai un esempio?

kingv
17-06-2003, 12:08
Originally posted by "Kleidemos"

ma fai un esempio?




import ecc.ecc.


HashMap hm = new HasMap();
hm.put("1", "uno");
hm.put("2", "due");

Iterator i = hm.keySet().iterator();

while(i.hasNext())
{
Object s = i.next();
System.out.println("Chiave: " + (String)s + " Valore: " + (String)hm.get(s));
}

Kleidemos
17-06-2003, 12:11
tnk 1000000000000000000