George Newton George Newton - 2 months ago 17
Java Question

Why Java grows ArrayList by 3/2?

Why does Java grow a full array by a factor of 3/2 instead of 2?

"The choice of a depends on the library or application: some textbooks
use a = 2, but Java's ArrayList implementation uses a = 3/2 and the C
implementation of Python's list data structure uses a = 9/8."

source wikipedia


In general, the choice of the growth factor depends mostly on experience and a good educated guess. You have to find the right balance between unecessary memory usage (for unused array space) and unecessary runtime usage (if the array has to be enlarged often). You also have to do this without knowing how big the list will be. The reason why it's 3/2 in Java is simply because someone thought it was the best.