This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi everyone I have an Array of Objects of type Result. One of the property of this Object is dictionary. I want to create a HashMap which keys are the different dictionaries and values are Array of Result that have the same dictionary property.
Use a MultiHashMap from Apache Commons. Or something similar.
The idea: 1) Map will be Map<Disctionary, List<Results>>. 2) When you get a Dictionary use map.get(dictionary) 3a) If the result is null, make a new List<Results> 3b) Add the current Results object to the List 3c) Put the List back in the Map keyed to the Dictionary
The MultiMap does this for you.
Joined: Nov 07, 2000
Sorry, should have read the question clearly. Modified code may look like,
And convert the List<Result> to Result whenever you want to use the array object. Or if you want to do then itself, loop through the Map, read each list and convert to array object.
As Steve mentioned, MultiHashMap does the same thing. [ August 19, 2008: Message edited by: Santhosh Kumar ]
Joined: Aug 18, 2005
thanks to both of you and for your quickness.
I was stuck with Array in my mind and didn't think about List.toArray(). [ August 19, 2008: Message edited by: Patrice Ricard ]