I am trying to parse a hashmap that contains name-value pairs…
The entities stored in the hashmap are words with a numerical value corresponding to each word.
This is the code that I am using:
hMap = (HashMap) untypedResult;
/*
get Collection of values contained in HashMap using
Collection values() method of HashMap class
*/
c = hMap.values();
//obtain an Iterator for Collection
Iterator itr = c.iterator();
//iterate through HashMap values iterator
while(itr.hasNext())
{
resp.getWriter().println(" Value= " + itr.next());
//resp.getWriter().println(" To String of iterator= " + itr.toString());
}
I am able to obtain the numerical values associated with each word using the above code. How do I obtain the value of each word as well?
This is the problem:
If you want the keys as well, you shouldn’t call
values(). CallentrySet()instead:Or for the raw type (ick):