Buscar en este blog

martes, 24 de junio de 2008

JAVA. Iterator. List, Set, Map

// la solución correcta
List list = new ArrayList();
Set set = new HashSet();
Map map = new TreeMap();

// la solución incorrecta
ArrayList list = new ArrayList();
HashSet set = new HashSet();
TreeMap map = new TreeMap();

JAVA. HttpServletRequest mostrar todos los parametros recibidos.

protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

// TMP debug
HashMap parametros = (HashMap) req.getParameterMap();
Iterator it = parametros.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
System.out.println(entry.getKey()+"="+entry.getValue());
}
// FIN TMP debug
}

==================================================

for ( Iterator iterator = aMap.entrySet ( ) .iterator ( ) ; iterator.hasNext ( ) ; ) {
Map.Entry entry = ( Map.Entry ) iterator.next ( ) ;
String key = ( String ) entry.getKey ( ) ;
String value = ( String ) entry.getValue ( ) ;
}