Enumeration e = ht.keys();
Object obj;
while (e.hasMoreElements()) {
obj = e.nextElement();
System.out.println("clave "+ obj +": " + ht.get(obj));
}
Enumeration e = ht.keys();
Object obj;
while (e.hasMoreElements()) {
obj = e.nextElement();
System.out.println("clave "+ obj +": " + ht.get(obj));
}
Muchas veces usamos el HashTable cuando deberíamos usar un HashMap, que no está sincronizado el acceso, y por tanto es más rápido.
Si, es cierto.
En las hash y list de java se ha tener muy claro que se quiere, ya que luego podemos tener algun pequeño problema de rendimiento en procesos grandes.
Gracias por la aportacíon
Pingback: Los números de 2010 « Fetishcode
Hola tengo un Problema al recorrer una hastable….
le muestro un ejemplo de lo que quiero hacer.
Hashtable numbers = new Hashtable();
numbers.put(“one”, new Integer(1));
numbers.put(“two”, new Integer(2));
numbers.put(“three”, new Integer(3));
ahora declaro otra Hashtable
Hashtable interna = new Hashtable();
interna.put(“uno”, “hola”);
interna.put(“dos”, “Hola de nuevo”);
continuo con la Hashtable numbers
number.put(“four”,interna); aca añado la nueva hastable interna con la clave “four”. esto anda bien.
lo que no puedo hacer es recorrerla.
osea si quiero hacer
number.get(“four”);
me devuelve una direccion de memoria
lo que nesecitaria es que alguien me pueda ayudar a convertir esa direccion en memoria en una hashtable de nuevo. Desde ya muchisimas gracias
Prueba de recorrerla asi
Iterator it = hm.entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next();
System.out.println(e.getKey() + ” ” + e.getValue());
}
fetishcode Muchisimas Gracias. tu sugerencia funciona muy bien,