java - Why ArrayList grows at a rate of 1.5, but for Hashmap it's 2? -
as per sun java implementation, during expansion, arraylist grows 3/2 it's initial capacity whereas hashmap expansion rate double. reason behind this?
as per implementation, hashmap, capacity should in power of two. may reason hashmap's behavior. in case question is, hashmap why capacity should in power of two?
the expensive part @ increasing capacity of arraylist copying content of backing array new (larger) one.
for hashmap, creating new backing array , putting map entries in new array. and, higher capacity, lower risk of collisions. more expensive , explains, why expansion factor higher. reason 1.5 vs. 2.0? consider "best practise" or "good tradeoff".
Comments
Post a Comment