Apart from your question, there’s a side thought I came up recently regarding iterating maps: probably it shouldn’t be done and could be a sign that we’re using the wrong data structure for the job. A map lets us lookup a value from a known key in O(1) time but when we iterate through its entries we’re searching in O(n) time. Yes this probably isn’t perceivable at all for a small number of elements, but I found myself many times having a map but only iterating its entries searching for some key or value: I think that’s not the correct usage of maps, where the best performance comes from knowing the key beforehand. So for these cases I think using binary search on an array or a binary search tree would be best suited. But again, this argument is moot for small sets and we’re lazy (I for one!), so we just use maps. 😄