1 hospital will have multiple doctors. and i need to know a java collection type(ArrayList,HashMap etc) where i could store hospital ID and a Doctor object in a suitable java collection type (ArrayList,HashMap etc).
The requirement is that i should be able to store the HospitalID as a key and the Doctor object as it’s value.
Furthermore, I should be able to have the same key for various Doctor object (as there can be many doctors working for the said hospital). So what is the java collection type (ArrayList,HashMap etc) where i can use for this scenario ?
Note: i can’t use a HashMap – because it takes unique IDs.
Later on i should be able to filter out all the doctors that work for a particular hospital (by searching from it’s ID) , and display its records
You can have an
ArrayListofDoctorobjects and then create aHashMapthat stores theHospitalIDas the key andArrayListof doctors as the value:UPDATE:
For adding new doctor :