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.
"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
posted 6 years ago
Thank you very much.
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad: