Since i'm working around time complexity, i've been searching through the oracle Java class library for the time complexity of some standard methods used on Lists, Maps and Classes. (more specifically, ArrayList, HashSet and HashMap)
Now, when looking at the HashMap javadoc page, they only really speak about the get()
and put()
methods.
The methods i still need to know are:
remove(Object o)
size()
values()
I think that remove()
will be the same complexity as get()
, O(1)
, assuming we don't have a giant HashMap with equal hashCodes, etc etc...
For size()
i'd also assume O(1)
, since a HashSet, which also has no order, has a size()
method with complexity O(1)
.
The one i have no idea of is values()
- I'm not sure whether this method will just somehow "copy" the HashMap, giving a time complexity of O(1)
, or if it will have to iterate over the HashMap, making the complexity equal to the amount of elements stored in the HashMap.
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…