Use an array when keys are small integers in a known range. If you need to count characters in a string, a size- array beats a hash map for speed and simplicity.
Use a hash map when keys are sparse, large, or non-numeric. Mapping strings to counts, storing coordinate pairs, or tracking objects by ID all require hashing.
The trade-off: arrays give access with no overhead, but waste space on sparse data. Hash maps handle any key type but have hashing overhead and potential collisions.