Reputation: 1817
Does The size of the Key of a Map have any kind of impact (eg in Performance) in any kind of Map implementation (eg HashMap)?
Would the following iteration be influenced by the Size of the Key object?
Map<Object, Object> map = new HashMap<Object, Object>();
//...
for(Map.Entry<Object, Object> entry : map.entrySet())
{
//...
}
Upvotes: 0
Views: 562
Reputation: 272417
I don't really understand what you mean by the 'size' of an object, given that an object can only contain primitives, and references to objects.
I would suspect that for a HashMap, the hashCode()
function will influence performance to some degree. Whether this depends on the size of the key depends on the implementation of hashCode()
. A similar proviso applies to the equals()
method.
Upvotes: 0
Reputation: 206996
No, the size of the key object does not matter for the performance of iterating a map.
Note that variables of non-primitive types are always references in Java (they're not the objects themselves, as in C++). It doesn't matter if the reference points to a small or a large object.
Upvotes: 1