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.
A Hashmap stores values as [key - value] pairs, where distinct keys act as 'references' for the values stored.
You should decide how you want to store the values. Usually for storing an object in a Map we store it as the value along with the ID for this element as the key.
i.e. hashmap.add(id, object);
Why is the requirement that the elements have to be stored in a Map? As they appear to be a heterogeneous collection I would think of a different collection (unless they are connected in some different way).
You can't append to a HashMap. They have no order so appending is meaningless.
You can add to a HashMap. The best way to do this would be to create a class to hold all the data you retrieve from the database, create an instance of this class for each batch of data that you retrieve and then put this instance into the HashMap using a suitable key value which needs to be unique.
Good point. Joanne mentioned creating a class to hold the data. That's what a bean (JavaBean) is. It contains fields and setters and getters, nothing else. In this case it would look something like this:
In the loop you'll do something like this:
I may have already told you more than I should have, so I'll stop here and let you take your next shot at it.