Monday, June 16, 2008

Iterate a Map in jdk1.5

We can Iterate a Map in jdk1.5 as follows:

public void testGetPersonTypeConstants()
{
Collection personTypeCollection = new Collection();
try{

Map constMap = DatabaseHelper.getPersonTypeConstantsList();

for(Entryentry : constMap.entrySet() )
{
System.out.println(entry.getKey()+": "+entry.getValue());
personTypeCollection.add(entry.getValue());
return personTypeCollection;
}
catch(Exception e)
{
rollbackTransaction();

return Collections.emptyList();
}

}

No comments: