Is it (performance-wise) better to use Arrays or HashMaps when the indexes of the Array are known? Keep in mind that the \'objects array/map\' in the example is just an exam
Logically, HashMap
is definitely a fit in your case. From performance standpoint is also wins since in case of arrays you will need to do number of string comparisons (in your algorithm) while in HashMap you just use a hash code if load factor is not too high. Both array and HashMap will need to be resized if you add many elements, but in case of HashMap you will need to also redistribute elements. In this use case HashMap loses.