| The issue is not so much one of wasting space but that we allocate the map in a size that is "too small" to hold all the elements we want it to hold, so it gets resized right away instead of being allocated with the right size from the beginning. One can have "each code path take responsibility", but as shown it's very easy to allocate maps too small when e.g. driving the initialization from a list. So having something as Guava's newArrayListWithExpectedSize() would be nice. Whether it makes any difference in the larger scheme of things? Probably not. So I'd rather shave different yaks  |