Thursday, December 13, 2012

Java: iterate through HashMap

Map resultMap = new HashMap();

ResultSet resultSetRegion = s.executeQuery(sSql2);
if(resultSetRegion.next()) {
    resultMap.put( "firstName", "" + resultSetRegion.getString("first_name") );
}

Iterator it = resultMap.entrySet().iterator();
while (it.hasNext()) {
    Map.Entry pairs = (Map.Entry) it.next();
    System.out.println("KEY: "+pairs.getKey()+"\tVALUE: "+pairs.getValue());
}

No comments:

Post a Comment