aspose file tools*
The moose likes Java in General and the fly likes Problem in iterating HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem in iterating HashMap" Watch "Problem in iterating HashMap" New topic
Author

Problem in iterating HashMap

Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Dear All,

I am facing an issue while iterating Hash Map. Through a query I am fetching list of users and list of emails of those users and i am adding those to a hash map as shown below:



But the valueMap object contains the required data from the database.
Request to please help me to resolve this issue


Cheers,
Keerthi Kumar N
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3436
    
  47

Why are you using an ArrayList as both a key and a value? The Map can hold multiple key-value pair on its own, you don't need to use lists to be able to put more keys/values into it. (Using a list as a key is very weird. And even if it had a merit in your case I don't see, it would still be dangerous, as the list is mutable; keys whose value can change cannot be used with a Map.)

The exception you're encountering is most likely caused because the utilDao.getUserEmailIds method is returning a null.

I'd suggest to read the Collections tutorial.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Martin Vajsar wrote: . . . keys whose value can change cannot be used with a Map. . . .
Oh, yes they can!

As long as you don’t mind all your references vanishing mysteriously whenever its hash code changes
 
 
subject: Problem in iterating HashMap
 
Similar Threads
How to use struts custom tags to handle this scenario?
in what ways can we change this formula..
How to Iterate HashMap of type HashMap<String, ArrayList<String>>
Newbie 'FreeMarker' template Question (usage of #list)
JSTL printing issue