This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Is it possible for a HashMap to use a Object as a key and the value be an ArrayList?
If it's valid, how would you obtain the Object information while iterating through the HashMap?
Would something like this work? Keeping in mind that the Object holds information like name, phone, address and the ArrayList would be a list of Contact Objects? I tried something like below but it didn't work.
If this is not a good idea, do you have a suggestion on what could be done differently?
Hi, your key is an Object, and value - ArrayLists - contains also Objects. Object does not have 'name' or 'contactname' properties (getters)
Try to declare HashMap like this:
Such code declares a HashMap, where keys are 'Person' class objects, and values are ArrayList object, and each element in this list is also a Person class object.
I'm not sure if it will work with JSP, but it is ok for plain java.